Write a processing instruction: . : XmlWriter « XML « C# / C Sharp

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.WriteAttributeString("genre", "Computer");
     writer.WriteAttributeString("ISBN", "1-1111-111");
     writer.WriteElementString("title", "C#");
     writer.WriteElementString("price", "9.9");
     writer.WriteCData("Prices 15% off!!");


Related examples in the same category

1.XmlWriter writes XML data out
2.Closes this stream and the underlying stream.
3.Creates a new XmlWriter instance using the specified stream.
4.Creates a new XmlWriter instance using the stream and XmlWriterSettings object.
5.Creates a new XmlWriter instance using the specified filename.
6.Creates a new XmlWriter instance using the specified TextWriter.
7.Creates a new XmlWriter instance using the TextWriter and XmlWriterSettings objects.
8.Flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.
9.Returns the closest prefix defined in the current namespace scope for the namespace URI.
10.Writes out all the attributes found at the current position in the XmlReader.
11.Writes an attribute with the specified local name, namespace URI, and value.
12.Encodes the specified binary bytes as Base64 and writes out the resulting text.
13.Encodes the specified binary bytes as BinHex and writes out the resulting text.
14.Writes out a block containing the specified text.
15.Closes one element and pops the corresponding namespace scope.
16.Copies everything from the reader to the writer
17.Copy everything from the XPathNavigator to writer.
18.Writes text content.
19.Writes a DateTime value.