IXMLDOMProcessingInstruction object

The IXMLDOMProcessingInstruction object represents a processing instruction, or information that specifies how an application should interpret an XML document. An example of a processing instruction is a document prolog, which specifies the XML version of a document. The prolog can also specify the character encoding of a document and whether a document requires additional information to be interpreted correctly.

Creating a processing instruction

Use the createProcessingInstruction method from the DOMDocument object to create a new processing instruction. You must supply the target value and its attributes. In the following example, the target value is “xml”, and the attribute is “version="1.0"”.

{Create a document prolog processing instruction.}
procInstruct = xmlDoc.createProcessingInstruction("xml", "version=" +  QUOTE +"1.0" + QUOTE);

Creating a processing instruction with the createProcessingInstruction method does not add the processing instruction to an XML document. You must add the processing instruction to an XML document or an element with the insertBefore method or the replaceChild method.

Adding a processing instruction

Use the insertBefore method to insert a processing instruction before the document element. You must specify the processing instruction as well as the document element.

{Add the processing instruction before the document element.}
xmlDoc.insertBefore(procInstruct, xmlDoc.documentElement);

A processing instruction can be added to either a DOMDocument object or an IXMLDOMElement object.

Retrieving a processing instruction

The childNodes collection contains all of the nodes in an XML document. You can retrieve a node from the childNodes collection with the item method by the index associated with the node. To find a processing instruction in the childNodes collection, retrieve each object as an IXMLDOMNode object, and then test the object’s node type with the nodeType property.

{Retrieve the first node in the childNodes collection and find out if it is an IXMLDOMProcessingInstruction object.}
node = element.childNodes.item[0];
if(node.nodeType = NODE_PROCESSING_INSTRUCTION) then
	procInstruct = node;
end if;

Replacing a processing instruction

Use the replaceChild method to replace a processing instruction or element in a document with a processing instruction. The processing instruction or element that you are replacing is returned.

{Replace the element with a processing instruction.}
element = xmlDoc.replaceChild(procInstruct, xmlDoc.documentElement);

Deleting a processing instruction

Use the removeNode method to remove a processing instruction from a document.

{Remove the processing instruction from the document.}

Documentation Feedback