Class XmlProcessingInstruction

System.Xml. XmlProcessingInstruction

Represents an XML processing instruction. Processing instructions are XML markup that represent instructions for the application handling the XML document, rather than data to be parsed.

Inheritance

class XmlProcessingInstruction : XmlLinkedNode

Remarks

A processing instruction has a target and data. The target is the application to which the instruction is directed. The data is the content of the instruction. For example, in the processing instruction <?xml-stylesheet type="text/xsl" href="style.xsl"?>, the target is "xml-stylesheet" and the data is "type="text/xsl" href="style.xsl"".

This class represents the processing instruction node within the XmlDocument object model.

Properties

Methods

Example

Creating and writing a processing instruction:


using System;
using System.Xml;

public class Example
{
    public static void Main(string[] args)
    {
        // Create a new XML document
        XmlDocument doc = new XmlDocument();

        // Create a processing instruction
        XmlProcessingInstruction pi = doc.CreateProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"style.xsl\"");

        // Append the processing instruction to the document
        doc.AppendChild(pi);

        // Create an XmlWriter to save the document
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        using (XmlWriter writer = XmlWriter.Create(Console.Out, settings))
        {
            doc.WriteTo(writer);
        }
    }
}
        

Output of the example:


<?xml-stylesheet type="text/xsl" href="style.xsl"?>