[C#]Unable to translate Unicode character \\u010B at index 53 to specified code page.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kendo
    New Member
    • Aug 2008
    • 3

    [C#]Unable to translate Unicode character \\u010B at index 53 to specified code page.

    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 file is small (< 1KB) there is no problem and the file it's saved correctly but if file it's big (> 500KB) I get this message?
    Can sombody help me?
    snippet:

    string strFile = @"c:\tmp\test.x ml";
    XmlWriter _xmlWriter;
    XmlWriterSettin gs settings = new XmlWriterSettin gs();
    settings.Encodi ng = Encoding.Defaul t;
    _xmlWriter = XmlWriter.Creat e(strFile, settings);
    xmlDoc.Save(_xm lWriter);
    _xmlWriter.Clos e();
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Is it because there is not a translation from those unicode characters to whatever the default encoding is?

    Comment

    • Kendo
      New Member
      • Aug 2008
      • 3

      #3
      Thank you :-)

      Yes, you're right. The Unicode character (\u010B) have no translation in default encoding (ISO-8859-1).

      But then the strange situation is when I have small file.

      I made xml file:
      <?xml version="1.0" encoding="UTF-8"?>
      <root>
      <text>textul: <chr>ċ</chr><dec>267</dec><hex>10B</hex><dec1>99</dec1></text>
      </root>

      where:
      <chr>-tag is Unicode character \u010B
      <dec>-tag is decimal code of character \u010B
      <hex>-tag is hexadecimal code of character \u010B

      this file it's save with the Unicode character translated to entity &#x010B;
      <?xml version="1.0" encoding="ISO-8859-1"?>
      <root>
      <text>textul: <chr>&#x010B;</chr><dec>267</dec><hex>10B</hex><dec1>99</dec1></text>
      </root>

      And when the file have exactly 79 more same <text> nodes :) I get the "ugly" message from thread subject :).

      What I do wrong? :-)

      Thanks in advance

      Comment

      • Kendo
        New Member
        • Aug 2008
        • 3

        #4
        well, I found how to :)
        here it is the answer: stackoverflow.c om
        Code:
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(@"<xml>™</xml>");
            using (MemoryStream ms = new MemoryStream())
            {
                XmlWriterSettings settings = new  XmlWriterSettings();
                settings.Encoding = Encoding.GetEncoding("ISO-8859-1");
                XmlWriter xw = XmlWriter.Create(ms, settings);
                doc.Save(xw);
                xw.Close();
                Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
            }

        Comment

        Working...