Returning XML natively in a .NET (C#) webservice? -


I realize that SOAP webservices. Web returns XML representation which returns the web method returns, but if I want to return the data formatting in XML what is the best object to store it?

I am using my XML to write, here is the code:

  Create XmlWriter author = XmlWriter (pathToOutput); Author.WriteStartDocument (); Writer.WriteStartElement ("people"); Author.WriteStartElement ("person"); Author. White attribute string ("name", "nick"); Writer.WriteEndElement (); Author.WriteStartElement ("person"); Author.WriteStartAttribute ("name"); Writer.WriteValue ("Nick"); Writer.WriteEndAttribute (); Writer.WriteEndElement (); Writer.WriteEndElement (); Writer.WriteEndDocument (); Writer.flush ();  

Now I can return this output to my calling webman as a string, but this & lt; String & gt; XML here & lt; / String & gt; , is still returning the full xml?

Please provide an example in your answer, that XML or other internal objects (if you consider XmlWriter a poor choice) with objects, there are many objects in the System.Xml package (namespace), but I have the object Are not able to highlight civil documents about how to use, or what situation to use.

In this way I am terminating it;

  stringbilder sb = new StringBuilder (); XmlWriter Author = XmlWriter.Create (SB, Settings); Author.WriteStartDocument (); Writer.WriteStartElement ("people"); Author.WriteStartElement ("person"); Author. White attribute string ("name", "nick"); Writer.WriteEndElement (); Author.WriteStartElement ("person"); Author.WriteStartAttribute ("name"); Writer.WriteValue ("Nick"); Writer.WriteEndAttribute (); Writer.WriteEndElement (); Writer.WriteEndElement (); Writer.WriteEndDocument (); Writer.flush (); XmlDocument xmlDocument = New XmlDocument (); XmlDocument.LoadXml (sb.ToString ()); Return xmlDocument;  

may not be the best way, but it appears to work. Tell me if you have a better way Thank you.


Comments