createProcessingInstruction Method

 

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

JScript Syntax

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

Parameters

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

data
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.

Example

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;  
xmlDoc.loadXML("<root><child/></root>");  
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));  
   WScript.Echo(xmlDoc.xml);  
}  

Output

  
<?xml version="1.0" ?>  
<root><child/></root>  

C/C++ Syntax

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

Parameters

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

data[in]
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

S_OK
The value returned if successful.

E_INVALIDARG
The value returned if the pi parameter is Null.

E_FAIL
The value returned if an error occurs.

Remarks

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.

Versioning

Implemented in: MSXML 3.0 and MSXML 6.0

Applies to

IXMLDOMDocument-DOMDocument

See Also

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