473,379 Members | 1,520 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,379 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 14912
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.