Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Developer's Guide

Working with Processing Instructions

Processing instructions provide a loosely-structured mechanism for conveying application-specific information within a document. Processing instructions can appear within document, element, document fragment, entity reference, or entity nodes. They have only two components—a name (also called the target) and a value. The value may contain content that looks like attribute values (often called pseudo-attributes), but this content is stored as simple text.

Processing instructions can appear in the document content—within the root element or an element that is the descendant of the root element—or they can appear before or after the root element. The <?xml-stylesheet?> processing instruction, used to connect XML documents to cascading style sheets or XSL Transformations (XSLT) style sheets, usually appears in the prolog.

Examples

JScript

The following JScript example identifies which style sheet to use in a processing instruction in the prolog.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var stylePI=xmlDoc.createProcessingInstruction("xml-stylesheet", 
  ' type="text/xsl" href="show_book.xsl"');
xmlDoc.appendChild(stylePI);

VBScript

Set xmlDoc = CreateObject("Msxml2.DOMDocument.5.0")
Set stylePI = xmlDoc.createProcessingInstruction("xml-stylesheet", 
  "type=""text/xsl"" href=""show_book.xsl""")
xmlDoc.appendChild(stylePI)

The XML document begins with the following.

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

The target of a processing instruction can be retrieved through its nodeName property while the rest of the processing instruction is stored in the nodeValue property. MSXML treats the XML declaration as a processing instruction within its DOM representation. This can have a significant effect on character encoding.

For more information about properties and methods of XMLDOMProcessingInstruction objects, see the IXMLDOMProcessingInstruction.