The XmlWriter class is an abstract base class that writes fast, forward-only, non-cached XML streams. The XmlWriter class also validates and verifies element and attribute names and ensures that the generated XML is well-formed.
The XmlWriter.Create static method creates the XML. The Create method has several
overloaded forms and can save the generated XML into various objects.We can use the Console.Out parameter with the XmlWriter.Create method to spit the XML out to the console.
XmlWriter writer = XmlWriter.Create(Console.Out);
The following code snippet creates an XML and spits it out to the console.
using (XmlWriter writer = XmlWriter.Create(Console.Out))
{
// Write Processing Instruction
String pi = "type=\"text/xsl\" href=\"book.xsl\"";
writer.WriteProcessingInstruction("xml-stylesheet", pi);
// Write DocumentType
writer.WriteDocType("book", null, null, "<!ENTITY h \"hardcover\">");
// Write a Comment

Comments
Join the conversation! Your thoughts help the community grow.