Mega Code Archive

 
Categories / C# / XML
 

Write a processing instruction

using System; using System.IO; using System.Xml; public class Sample {   private const string filename = "sampledata.xml";   public static void Main() {      XmlWriterSettings settings = new XmlWriterSettings();      settings.Indent = true;      XmlWriter writer = XmlWriter.Create(filename, settings);      String PItext="type=\"text/xsl\" href=\"book.xsl\"";      writer.WriteProcessingInstruction("xml-stylesheet", PItext);      writer.WriteDocType("book", null , null, "<!ENTITY h \"hardcover\">");      writer.WriteComment("sample XML");      writer.WriteStartElement("book");      writer.WriteAttributeString("genre", "Computer");      writer.WriteAttributeString("ISBN", "1-1111-111");      writer.WriteElementString("title", "C#");      writer.WriteStartElement("style");      writer.WriteEntityRef("h");      writer.WriteEndElement();       writer.WriteElementString("price", "9.9");      writer.WriteCData("Prices 15% off!!");      writer.WriteEndElement();      writer.WriteEndDocument();      writer.Flush();      writer.Close();     } }