473,216 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,216 software developers and data experts.

Unable to translate Unicode character \u00E9 at index 5409 to specified code page.

I've got some C# 2.0 code that has been working for a year.

using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) {
// many lines of code to write to w
w.WriteStartElement("contactTypeRef");

Suddently, I'm getting this 100% repeatable error:

************** Exception Text **************
System.Text.EncoderFallbackException: Unable to translate Unicode character
\u00E9 at index 5409 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Xml.CharEntityEncoderFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Text.EncoderFallbackBuffer.InternalFallback (Char ch, Char*& chars)
at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte*
bytes, Int32 byteCount, EncoderNLS encoder)
at System.Text.EncoderNLS.Convert(Char* chars, Int32 charCount, Byte* bytes,
Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean&
completed)
at System.Text.EncoderNLS.Convert(Char[] chars, Int32 charIndex, Int32
charCount, Byte[] bytes, Int32 byteIndex, Int32 byteCount, Boolean flush, Int32&
charsUsed, Int32& bytesUsed, Boolean& completed)
at System.Xml.XmlEncodedRawTextWriter.EncodeChars(Int 32 startOffset, Int32
endOffset, Boolean writeAllToStream)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.RawText(String s)
at System.Xml.XmlEncodedRawTextWriter.WriteStartEleme nt(String prefix, String
localName, String ns)
at System.Xml.XmlWellFormedWriter.WriteStartElement(S tring prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)

I thought the whole point of using an XmlWriter was that it would translate the
chars into legal XML.

How can I resolve this?
--
Thanks in advance, Les Caudle
Jun 20 '07 #1
5 14894
Les Caudle wrote:
I've got some C# 2.0 code that has been working for a year.

using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) {
// many lines of code to write to w
w.WriteStartElement("contactTypeRef");

Suddently, I'm getting this 100% repeatable error:

************** Exception Text **************
System.Text.EncoderFallbackException: Unable to translate Unicode character
\u00E9 at index 5409 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Xml.CharEntityEncoderFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Text.EncoderFallbackBuffer.InternalFallback (Char ch, Char*& chars)
at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte*
bytes, Int32 byteCount, EncoderNLS encoder)
at System.Text.EncoderNLS.Convert(Char* chars, Int32 charCount, Byte* bytes,
Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean&
completed)
at System.Text.EncoderNLS.Convert(Char[] chars, Int32 charIndex, Int32
charCount, Byte[] bytes, Int32 byteIndex, Int32 byteCount, Boolean flush, Int32&
charsUsed, Int32& bytesUsed, Boolean& completed)
at System.Xml.XmlEncodedRawTextWriter.EncodeChars(Int 32 startOffset, Int32
endOffset, Boolean writeAllToStream)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.RawText(String s)
at System.Xml.XmlEncodedRawTextWriter.WriteStartEleme nt(String prefix, String
localName, String ns)
at System.Xml.XmlWellFormedWriter.WriteStartElement(S tring prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)

I thought the whole point of using an XmlWriter was that it would translate the
chars into legal XML.
Are you perhaps trying to write out XML in an encoding like US-ASCII
that does not include the character 'é'?
What are you XmlWriterSettings exactly when you get that error?
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 20 '07 #2
On Wed, 20 Jun 2007 17:05:24 +0200, Martin Honnen <ma*******@yahoo.dewrote:
>Les Caudle wrote:
>I've got some C# 2.0 code that has been working for a year.

using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) {
// many lines of code to write to w
w.WriteStartElement("contactTypeRef");

Suddently, I'm getting this 100% repeatable error:

************** Exception Text **************
System.Text.EncoderFallbackException: Unable to translate Unicode character
\u00E9 at index 5409 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Xml.CharEntityEncoderFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Text.EncoderFallbackBuffer.InternalFallback (Char ch, Char*& chars)
at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte*
bytes, Int32 byteCount, EncoderNLS encoder)
at System.Text.EncoderNLS.Convert(Char* chars, Int32 charCount, Byte* bytes,
Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean&
completed)
at System.Text.EncoderNLS.Convert(Char[] chars, Int32 charIndex, Int32
charCount, Byte[] bytes, Int32 byteIndex, Int32 byteCount, Boolean flush, Int32&
charsUsed, Int32& bytesUsed, Boolean& completed)
at System.Xml.XmlEncodedRawTextWriter.EncodeChars(Int 32 startOffset, Int32
endOffset, Boolean writeAllToStream)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.RawText(String s)
at System.Xml.XmlEncodedRawTextWriter.WriteStartEleme nt(String prefix, String
localName, String ns)
at System.Xml.XmlWellFormedWriter.WriteStartElement(S tring prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)

I thought the whole point of using an XmlWriter was that it would translate the
chars into legal XML.

Are you perhaps trying to write out XML in an encoding like US-ASCII
that does not include the character 'é'?
What are you XmlWriterSettings exactly when you get that error?

Martin - Yes, I'm using Encoding.ASCII.

If I output to UTF8 encoding, all is fine, but NetSuite will no longer import
the XML. So, I need to find a way to automate creating the XML formatted as
ASCII.

Here are the settings:

settings.NewLineChars = @"\r\n";
settings.NewLineHandling = NewLineHandling.Replace;
settings.NewLineOnAttributes = true;
settings.Encoding = Encoding.ASCII;

Thanks, Les Caudle
Jun 20 '07 #3
Les Caudle wrote:
Martin - Yes, I'm using Encoding.ASCII.

If I output to UTF8 encoding, all is fine, but NetSuite will no longer import
the XML. So, I need to find a way to automate creating the XML formatted as
ASCII.

Here are the settings:

settings.NewLineChars = @"\r\n";
settings.NewLineHandling = NewLineHandling.Replace;
settings.NewLineOnAttributes = true;
settings.Encoding = Encoding.ASCII;
Any XML parser/application is supposed to support UTF-8 and UTF-16 but
not ASCII.
I don't think XmlWriter can do what you want unless your code manually
makes sure it writes out non-ASCII characters as character references
e.g. like this

xmlWriter.WriteStartElement("foo");
foreach (char c in "Je suis fatigué.") {
if (c < 128) {
xmlWriter.WriteString(c.ToString());
}
else {
xmlWriter.WriteCharEntity(c);
}
}
xmlWriter.WriteEndElement();

that then results in

<foo>Je suis fatigu&#xE9;.</foo>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 21 '07 #4
Martin Honnen wrote:
Any XML parser/application is supposed to support UTF-8 and UTF-16 but
not ASCII.
I don't think XmlWriter can do what you want unless your code manually
makes sure it writes out non-ASCII characters as character references
Another solution could be to generate the XML in UTF-8 or UTF-16 first,
then to apply an XSLT styleshet like this

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" encoding="US-ASCII"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

with .NET XslCompiledTransform. That way .NET seems to be able to ensure
the output is US-ASCII by using character references as needed for
characters that are outside of the target encoding.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 21 '07 #5
Hello Les Caudle,

I totally agree with Martin.

ASCIIEncoding object cannot encode a character whose Unicode code point
value is outside the range U+0000 to U+007F.
According to the error message you pasted, WriteStartElement() method want
to write an illegal character (\u00E9 ¨¦) into ASCII encoded XML file. Thus
.net runtime throw an EncoderFallbackException.

Have you tried Martin's suggestion so far? Does this method works for you?
If you face any further issue, please update here. Thus we could follow up.
:)

Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: nicolas.riesch | last post by:
I am trying to use strxfm with unicode strings, but it does not work. This is what I did: >>> import locale >>> s=u'\u00e9' >>> print s é >>> locale.setlocale(locale.LC_ALL, '')...
27
by: EU citizen | last post by:
Do web pages have to be created in unicode in order to use UTF-8 encoding? If so, can anyone name a free application which I can use under Windows 98 to create web pages?
11
by: Patrick Van Esch | last post by:
Hello, I have the following problem of principle: in writing HTML pages containing ancient greek, there are two possibilities: one is to write the unicode characters directly (encoded as two...
24
by: chri_schiller | last post by:
I have a home-made website that provides a free 1100 page physics textbook. It is written in html and css. I recently added some chinese text, and since that day there are problems. The entry...
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
6
by: geegeegeegee | last post by:
Hi All, I have come across a difficult problem to do with extracting UniCode characters from RTF strings. A detailed description of my problem is below, if anyone could help, it would be much...
3
by: amija0311 | last post by:
Hi, I am new using DB2 9.1 database by windows base. I want to query the data that contain string then translate the string into integer using DB2. The problems is If the data is null, i got the...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
3
by: Kendo | last post by:
I have this strange message when I try to save XML-file with XmlWriter: "Unable to translate Unicode character \\u2009 at index 478 to specified code page." Why it's strange? Because when the...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.