There are four main objects included with Internet Explorer 5's implementation of the XML DOM: XMLDOMDocument, XMLDOMNode, XMLDOMNodeList, and XMLDOMNamedNodeMap. In addition, sixteen other objects are part of Internet Explorer 5's implementation of the XML DOM. All of these objects have properties and methods that you can use to gather information about the document (including its structure) and to navigate to other object nodes within a document tree. A node is a reference to any object that can exist in a document hierarchy. The ability to access different nodes of the document tree is a function that is also available using XPath and XPointer. Twelve different types of nodes are available in the DOM: element, attribute, text, CDATA section, entity reference, entity, processing instruction, comment, document, document type, document fragment, and notation. An interface exists for each of these node types that allows you to gather and manipulate information on the node. The most common node types are the element, attribute, and text nodes.
Attributes are not actually child elements of any node in the tree, so they have a special programming interface called IXMLDOMNamedNodeMap.
The W3C DOM specification defines two types of programming interfaces: fundamental and extended. The fundamental DOM interfaces are required when writing applications that manipulate XML documents. The extended interfaces are not required, but make it easier for developers to write applications. The Internet Explorer 5 DOM implements both the fundamental and extended interfaces. In addition, it provides other interfaces to support Extensible Stylesheet Language (XSL), XSL patterns, namespaces, and data types.
For script developers, the most important object in the Internet Explorer 5's implementation of the XML DOM is the XMLDOMDocument object, which allows developers to navigate, query, and modify the content and structure of an XML document. This object implements the IXMLDOMDocument interface. We will look at this object first.
To navigate and get a reference to an XML document, you need to use the XMLDOMDocument object. Once you actually get a reference to the document, you can begin to work with it. The XMLDOMDocument object implements the IXMLDOMDocument interface.
Getting a reference to an XML document
Depending on the programming language you are using, you can get a reference to an XML document in several ways.
In Microsoft JScript, you can get a reference as follows:
var objXMLdoc = new ActiveXObject("Microsoft.XMLDOM); objXMLdoc.load("http://www.northwindtraders.com/sales.xml");
In VBScript, the code for obtaining a reference appears as follows:
Dim objXMLdoc Set objXMLdoc = CreateObject("Microsoft.XMLDOM") objXMLdoc.load("http://www.northwindtraders.com/sales.xml")
In Microsoft Visual Basic, you should add a reference to Msxml.dll to your project by choosing References from the Project menu, and then choosing Microsoft XML version 2 from the References dialog box. The code to get a reference to an XML document appears as follows:
Dim objXMLdoc As DomDocument Set objXMLdoc = New DomDocument objXMLdoc.load("http://www.northwindtraders.com/Sales.xml")
You could also use the following code without setting the reference, though the above method is preferable:
Set objXMLdoc = CreateObject("Microsoft.XMLDOM") objXMLdoc.load("http://www.northwindtraders.com/Sales.xml")