Search code examples
c#xmlxmldocument

Get data for XmlDocument in C#


I want to read entire data/all nodes from XmlDocument. I don't want to use InnerXml/OuterXml properties. Any other way to read from XmlDocument ?. Below example I have get data using OuterXml property, but I don't want to use Outerxml.

Ex:

     XmlDocument ACTGraphicalXMLDoc = new XmlDocument();
     ACTGraphicalXMLDoc.LoadXml(ACTConfigXML);

     StringBuilder ConfigXML = new StringBuilder();
     ConfigXML.Append(ACTGraphicalXMLDoc.OuterXml);
     string ConfigXML2 = ConfigXML.ToString();

Solution

  • You can try the following:

    StringWriter sw = new StringWriter();
    XmlTextWriter tx = new XmlTextWriter(sw);
    ACTGraphicalXMLDoc.WriteTo(tx);
    sw.ToString();