Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to string

Status
Not open for further replies.

Chance1234

IS-IT--Management
Joined
Jul 25, 2001
Messages
7,871
Location
US
I have a XML file , for arguments sake its

Code:
<XML>
  <country>France</country> 
  <country>Spain</country> 
  </XML>


What i want to do is return that as a string so my output would be

Code:
"<xml><country>France</country><country>Spain</country></XML>


I can see how to get certain nodes etc using XmlDocument doc = new XmlDocument(); but i cant see a way of passing the whole file.,

many thanks





Chance,

Filmmaker, gentleman and polla stilo eleous
 
If all you need is an XML string (not an XML file), my first thought was just to open the file as a text stream and read it in that way.

I don't have time to read this article atm (gotta get to work) but it looks like it may be worth looking into (about the XmlTextReader object)
Hope it helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
got it wokring with the followng

Code:
string fname = "xml/Test4.xml";

        XmlReaderSettings settings = new XmlReaderSettings();
        settings.IgnoreWhitespace = true;
        using (XmlReader reader = XmlReader.Create(MapPath(fname)))
        {
            reader.MoveToContent();
            reader.Read();

            string stest = reader.ReadInnerXml()

Chance,

Filmmaker, gentleman and polla stilo eleous
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top