Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

createProcessingInstruction Method


Creates a processing instruction node that contains the supplied target and data.

var objXMLDOMProcessingInstruction =   
oXMLDOMDocument.createProcessingInstruction(target, data);  


A string specifying the target part of the processing instruction. This supplies the nodeName property of the new object.

A string specifying the rest of the processing instruction preceding the closing ?> characters. This supplies the nodeValue property for the new object.

Return Value

An object. Returns the new IXMLDOMProcessingInstruction object.


The following script example specifies the target string "xml" and the data string "version=\"1.0\"" to generate the processing instruction <?XML version="1.0"?>.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");  
var pi;  
xmlDoc.async = false;  
if (xmlDoc.parseError.errorCode != 0) {  
   var myErr = xmlDoc.parseError;  
   WScript.Echo("You have error " + myErr.reason);  
} else {  
   pi = xmlDoc.createProcessingInstruction("xml", "version=\"1.0\"");  
   xmlDoc.insertBefore(pi, xmlDoc.childNodes.item(0));  


<?xml version="1.0" ?>  

HRESULT createProcessingInstruction(  
    BSTR target,  
    BSTR data,  
    IXMLDOMProcessingInstruction **pi);  


The target part of the processing instruction. It supplies the nodeName property of the new object.

The remainder of the processing instruction preceding the closing ?> characters. It supplies the nodeValue property for the new object.

pi[out, retval]
The address of the new IXMLDOMProcessingInstruction object.

Return Values

The value returned if successful.

The value returned if the pi parameter is Null.

The value returned if an error occurs.

Creating a processing instruction node with this method is the same as using createNode where the Type parameter value is NODE_PROCESSING_INSTRUCTION and no namespace is specified. You cannot specify a namespace with the createProcessingInstruction method.

Although this method creates the new object in the context of this document, it does not automatically add the new object to the document tree. In other words, although the ownerDocument property of the new node points to this document object, the parentNode property is set to Null. To add the new object, you must explicitly call one of the node insert methods, insertBefore method, replaceChild method, or appendChild method.

The new object's nodeType property has the value NODE_PROCESSING_INSTRUCTION.

Implemented in: MSXML 3.0 and MSXML 6.0


nodeName Property1
nodeType Property1
nodeValue Property
createNode Method
ownerDocument Property
insertBefore Method
replaceChild Method
appendChild Method

© 2017 Microsoft