The Document Object Model (DOM) as implemented in MSXML provides a programmatic representation of XML documents, fragments, nodes, or node-sets. It also provides an application programming interface for working with XML data. As an XML representation, it conforms to the W3C DOM specification. As a set of API, XML DOM objects are COM objects that implement interfaces and can be used in XML applications written in programming languages such as C/C++, Visual Basic, VBScript, and JScript.
The following JScript fragments outline the basic process of programming with XML DOM.
var xmldoc = new ActiveXObject("Msxml2.DOMDocument");
xmldoc.load("file.xml");
strXML = "<a><a1>1</a1><a2>2</a2></a>";
xmldoc.loadXML(strXML);
var node = xmldoc.selectSingleNode("//a2");
<a3>
element as a new child of the document element, <a>
:
xmldoc.documentElement.appendChild( xmldoc.createElement("a3") );
save
method on the object:
xmldoc.save( "new.xml" );
transformNode
method on the DOM object for the XML document:
var xslt = new ActiveXObject("msxml2.DOMDocument"); xslt.load("transform.xsl"); strXML = xmldoc.transformNode(xslt);
These are just a few simple examples to show you how DOM can be used to work with an XML document. More detailed discussions and demonstrations are provided in the later sections of this guide.
Concepts | How Do I? | DOM Reference
W3C Document Object Model (DOM) Level 1 Specification (Second Edition)