Parse a xml file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Francone
    New Member
    • Mar 2007
    • 1

    Parse a xml file

    Hi.

    I'm trying to parse in c# DotNet a xml file (file.FullName) that as no encoding type, and one of the tag is compose with 'ç' or 'é' or 'ã'
    but in the c# DotNet declaration of the var new_s those characters not appear !

    See example:
    xml file.FullName:
    ---------------------------------------------------------------------------------------------
    <?xml version="1.0" ?>
    <XML_CLASS>
    <Report>
    <![CDATA[serviço , or, Coronárias
    ]]>
    </Report>
    </XML_CLASS>

    C#:
    XmlSerializer s = new XmlSerializer(t ypeof(XML_CLASS ));
    StreamReader stream = new StreamReader(fi le.FullName);
    confFile = (XML_CLASS)s.De serialize(strea m);

    string new_s = confFile.Report .ToString();
    ---------------------------------------------------------------------------------------------
    In string new_s the characters 'ç' or 'é' or ' í ' or 'ã' not appear!
    Can someone help me?

    Thanks to all.
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    Welcome to TSDN...

    Try to set the stream this way (for encoding "ISO-8859-1"):
    Code:
    StreamReader stream = new StreamReader(file.FullName, System.Text.Encoding.GetEncoding(28591));
    I could not test with XML_CLASS class, but it displays correctly with:
    Code:
    Console.WriteLine(stream.ReadToEnd());

    Comment

    • dorinbogdan
      Recognized Expert Contributor
      • Feb 2007
      • 839

      #3
      Hi,
      Did you succeed to solve the problem ?
      If yes, please let me know, in order to close the thread.
      Thanks,
      Dorin.

      Comment

      Working...