Search code examples
c#xml.net-2.0

XMLDocument to xml file


In my web services I am sending a XML document using this code,

      XmlDocument doc = new XmlDocument();
      doc.LoadXml(myBigData.Serialize());
      return result = doc.DocumentElement;

Now In my c# console app I am calling this web method using,

      XmlElement returnedDataFromWebMethod = myWbSercvices.WebMethod();

Now how can I convert this XML element to a xml file e.g. in my C drive so i can see if xml document as document, instead of going through it using foreach(XMLNode)


Solution

  • You may try this:

    var doc = new XmlDocument();
    var node = doc.ImportNode(returnedDataFromWebMethod, true);
    doc.AppendChild(node);
    doc.Save("output.xml");