سؤال

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)

هل كانت مفيدة؟

المحلول 2

You may try this:

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

نصائح أخرى

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top