read xml fail

Discussion in 'ASP .Net Web Controls' started by haiwen, Jan 15, 2004.

  1. haiwen

    haiwen Guest

    Hello, every one:

    I have a xml file include:

    <temperature> 150°F</temperature>

    When I use the DataSet's readXML function. I get error
    message that ° is an invalid character!

    Another problem is how to handle the ... special character
    of Word2000 in C#, just like the Tab is \t

    Could anyone help?


    Best Wishes,

    Haiwen
    haiwen, Jan 15, 2004
    #1
    1. Advertising

  2. Hi Haiwen,

    Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
    assisting you on this issue.
    Based on my understanding, there is <temperature> 150¡ãF</temperature> in
    your xml file, when you use DataSet.ReadXml method to read this xml file,
    "invalid character" error generate.

    ====================
    Based on my research, the problem may occur if your xml file was saved with
    encoding type: ANSI.
    Because your "150¡ãF" characters are Unicode encoded, while stored as ANSI,
    you can not read it correctly.

    You can try the following Steps/ Solution to see if it helps resolve your
    issue:
    1). Use NotePad.exe to open your xml file
    2). Use "Save As" menu option
    3). In the "Save As" dialog box, choose Encoding type: Unicode
    4). Save your xml as a new xml file name, such as newxml.xml

    Then I think your application can read this xml file correctly(Because .Net
    default use Unicode encoding way to read xml file)
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    ====================
    For further information, in the xml file's declaration node, you can
    specify your xml file's encoding way, such as:
    <?xml version="1.0" encoding="UTF-16" ?>

    You can use .Net class XmlDeclaration to manipulate the XML declaration
    node.
    XmlDeclaration has a property Encoding can Gets or sets the encoding level
    of the XML document, please refer to:
    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlXmlDeclarat
    ionClassEncodingTopic.asp

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 16, 2004
    #2
    1. Advertising

  3. Hi Haiwen,

    Thanks very much for your feedback.I am glad it works.

    =======================================================
    For your further concern of converting Ansi XML file into Unicode encoding
    format, I think you can refer to the StreamWriter class whoes constructor
    takes one Encoding parameter.

    Then, you can pass the StreamWriter to DataSet.WriteXml() method as
    parameter.

    Sample code like this:

    dataSet11.ReadXml("D:\\test.xml");
    TextWriter tw=new
    StreamWriter("D:\\newtest.xml",false,System.Text.Encoding.Unicode);
    dataSet11.WriteXml(tw);

    ========================================================
    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.
    Hope you have a nice experience on using Microsoft Newsgroup!

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Jan 21, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chumley Walrus

    Valid xml to read from an xml file?

    Chumley Walrus, Dec 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    408
    Peter Rilling
    Dec 28, 2005
  2. Wenjie

    if (f() != FAIL) or if (FAIL != f())?

    Wenjie, Jul 28, 2003, in forum: C Programming
    Replies:
    3
    Views:
    430
    E. Robert Tisdale
    Jul 31, 2003
  3. haiwen

    xml file write fail???

    haiwen, Jul 17, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    213
    Yan-Hong Huang[MSFT]
    Jul 22, 2003
  4. reeddeer
    Replies:
    5
    Views:
    188
    Martin Kissner
    Mar 13, 2005
  5. Erik Wasser
    Replies:
    5
    Views:
    437
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page