XML.XMLDocument (Property)

A reference to the top of a DOM hierarchy that describes the content of the XML data island.


JScript - 5.0
Internet Explorer - 5.0
JavaScript syntax:IEmyXML.XMLDocument

Given the example of a block of XML in an HTML document:

   <XML ID="myBlock">
   <ABSTRACT>This is an example block of text.</ABSTRACT>

individual nodes in that so called data island can be accessed through this XMLDocument property. The object returned by this property responds to the selectSingleNode() method. The argument to this is the slash separated path to the node within the document you are looking for. The slash separated values are the XML tagnames used to construct the document.

In this example, they all begin with the string "METADATA" and since the document only contains one layer inside that, all nodes can be reached with the following strings:

Given that our XML block has an ID value of "myBlock" this line of script code should yield a reference to an object that encapsulates the <ABSTRACT> node:


Having accessed the DOM node you want, its content can be examined by looking at its text property.

The example code illustrates this concept as it might be assembled together in a simple form.


Example code:

   <!-- Create an XML island -->
   <XML ID="myBlock">
   <ABSTRACT>This is an example block of text.</ABSTRACT>
   // Get the DOM document
   myXMLDocument = myBlock.XMLDocument;
   // Find the node
   myNode = myXMLDocument.selectSingleNode("METADATA/ABSTRACT");
   // Display the text in the node
   // Now access node attributes and content
   myOwner = myXMLDocument.getElementsByTagName('OWNER')[0];
   alert(myOwner.getAttribute('TYPE') + ': ' + myOwner.text);