What is XML DOM? |
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 that support COM.
The following PowerBASIC code fragments outline the basic process of programming with XML DOM.
DIM pXMLDoc AS IXMLDOMDocument pXMLDoc = NEWCOM "Msxml2.DOMDocument.6.0"
pXMLDoc.load "books.xml"
bstrXML = UCODE$("<a><a1>1</a1><a2>2</a2></a>") pXmlDoc.loadXml bstrXML
DIM pNode AS IXMLDOMNode pNode = pXmlDoc.selectSingleNode(UCODE$("//a2"))
DIM pRootElement AS IXMLDOMElement DIM pNewElement AS IXMLDOMElement pRootElement = pXmlDoc.documentElement pNewElement = pXmlDoc.createElement(UCODE$("a3")) pRootElement.appendChild pNewElement
pXmlDoc.save "new.xml"
DIM pXslt AS IXMLDOMDocument pXslt = NEWCOM "Msxml2.DOMDocument.6.0" pXslt.load "transform.xsl" bstrXML = pXmlDoc.transformNode(pXslt)
These are just a few simple examples to show you how DOM can be used to work with an XML document.
|