Search code examples
c#xmlxmldocument

Read XML file into XmlDocument


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.


Solution

  • 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;