Read XML file into XmlDocument

AJP picture AJP · Feb 2, 2012 · Viewed 279.2k times · Source

I am very new to C#. I have XML file (text.xml). I want to read that in XmlDocument and store the stream in string variable.

Answer

Timur Sadykov picture Timur Sadykov · Feb 2, 2012

Use XmlDocument.Load() method to load XML from your file. Then use XmlDocument.InnerXml property to get XML string.

XmlDocument doc = new XmlDocument();
doc.Load("path to your file");
string xmlcontents = doc.InnerXml;