Home > DeveloperSection > Forums > Read xml as a string
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    January-27-2014 3:09 AM

 C# C# 
Ratings:


 1 Reply(s)
 803  View(s)
Rate this:

I have an xml file which i need to read and store it as a string.

Below is my content in xml.

<list>

<SlideShow id="12523" languageadded="sv" publish="1">

 <name language="sv">Ann-Marie från SWE</name>

</SlideShow>

</list>

And i am using below code to read,

FileStream fStream = new FileStream(path);

StreamReader sr = new StreamReader(fStream);

ItemController.cacheTG = sr.ReadToEnd();

sr.Close();

fStream.Close();

But when i read tghe special character in the name field "Ann-Marie från SWE" converts to Ann-Marie fr?n SWE. How to read the xml without changing special characters.



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-27-2014 3:24 AM

Hi Jacob,

This is due to encoding. You need to specify the encoding (UTF8) like this:

FileStream fStream = new FileStream(path);

StreamReader sr = new StreamReader(fStream, System.Text.UTF8Encoding);

ItemController.cacheTG = sr.ReadToEnd();

sr.Close();

fStream.Close();

Don't want to miss updates? Please click the below button!

Follow MindStick