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 eg in my C drive so i can see if xml document as document, instead of going through it using foreach(XMLNode)
create a new XmlDocument:
XmlDocument doc = new XmlDocument();
call your web method and save it in an XmlNode
XmlNode returnedDataFromWebMethod = myWbSercvices.WebMethod();
append your element
doc.AppendChild(returnedDataFromWebMethod);
save the document
doc.Save("result.xml");
You can use XmlWriter and WriteTo method. http://msdn.microsoft.com/en-us/library/system.xml.xmlelement.writeto.aspx
Example:
XmlWriterSettings xmlSetings = new XmlWriterSettings();
xmlSetings.Indent = true;
xmlSetings.Encoding = Encoding.ASCII;
XmlWriter writer = XmlWriter.Create(@"C:\someFile.xml", xmlSetings);
returnedDataFromWebMethod.WriteTo(writer);
You may try this:
var doc = new XmlDocument();
var node = doc.ImportNode(returnedDataFromWebMethod, true);
doc.AppendChild(node);
doc.Save("output.xml");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.