ProcessingInstruction Object
Last Updated: 08-26-2005
Represents an XML processing instruction in the Document Object Model (DOM).

Remarks
The ProcessingInstruction object is a specialized node object in an XML document that contains a processing instruction.
Prior to revision 3, processing instruction nodes are not accessible via the DOM. In revision 3 and later, they are accessible.
Examples

Consider the following sample XML document that includes several processing instructions:

<?xml version="1.0"?>
<?access-control allow="*"?>
<?Magnum is a type of gun?>
<?PI "is the ratio of the circumference of a circle to its diameter"?>
<?Magnum P.I. was an '80s TV show?>
<doc>
    Document stuff goes here...
</doc>

Here is a program that could be used to process the XML document. It traverses the document to determine the number of processing instruction nodes and to gather their content. Finally, it states the number of processing instruction nodes and enumerates them, reporting for each the type of processing instruction it is (oValue.target) and its content (oValue.data).

<vxml version="2.1"
  xmlns="http://www.w3.org/2001/vxml">

   <data name="dom" src="pisample.xml"/>

   <script>
   <![CDATA[
   var aValues = [];
   try {
      for (var i = 0; i < dom.childNodes.length; i++)
      {
         var oNode = dom.childNodes.item(i);
         if (oNode.nodeType == Node.PROCESSING_INSTRUCTION_NODE)
            aValues.push({'target' : oNode.target, 'data' : oNode.data});
      }
   }
   catch(e)
   { vxmllog("Exception: " + e); }
   ]]>
   </script>

   <form>
      <block>
         <prompt>The document has <value expr="aValues.length"/> 
            processing instruction nodes.</prompt>
         <break size="small"/>
         <var name="j" expr="0"/>
         <foreach item="oValue" array="aValues">
            <assign name="j" expr="j+1"/>
            <prompt>Number <value expr="j"/></prompt>
            <break size="small"/>
            <prompt><value expr="oValue.target"/></prompt>
            <prompt><value expr="oValue.data"/></prompt>
            <break size="small"/>
         </foreach>
      </block>
   </form>
</vxml>


[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers