180 likes | 218 Views
Parsing with DOM using MSXML. Kanda Runapongsa ( krunapon@kku.ac.th ) Dept. of Computer Engineering Khon Kaen University. XML DOM. The XML Document Object Model (DOM) is a Programming Interface for XML documents It defines the way an XML document can be accessed and manipulated
E N D
Parsing with DOM using MSXML Kanda Runapongsa (krunapon@kku.ac.th) Dept. of Computer Engineering Khon Kaen University
XML DOM • The XML Document Object Model (DOM) is a Programming Interface for XML documents • It defines the way an XML document can be accessed and manipulated • It is designed to be used with several programming languages and any operating system 168493: XML and Web Services (II/2546)
Introduction to DOM • A program called an XML parser can be used to load an XML document into the memory • When the document is loaded, its information can be retrieved and manipulated by accessing the DOM 168493: XML and Web Services (II/2546)
Overview of DOM • The DOM represents a tree view of the XML document • The documentElement is the top-level of the tree • This element has one or many childNodes that represent the branches of the tree 168493: XML and Web Services (II/2546)
The Microsoft XML Parser • Supports JavaScript, VBScript, Perl, VB, Java, C++ and more • Supports W3C XML 1.0, XML DOM, and SAX • Supports DTD and XSD • The Microsoft XML parser is a COM component that comes with Microsoft Internet Explorer 168493: XML and Web Services (II/2546)
Creating an XML Document Object • Javascript • var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") • VBScript • set xmlDoc = CreateObject("Microsoft.XMLDOM") 168493: XML and Web Services (II/2546)
Loading an XML File <script type="text/javascript"> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load(“cdcatalog.xml") // ....... processing the document goes here </script> 168493: XML and Web Services (II/2546)
DOM Node • The node object represents a node in the node tree. • A node can be an element node, a text node, or any other of the node types • All of these node types have properties and methods 168493: XML and Web Services (II/2546)
DOM Node Properties 168493: XML and Web Services (II/2546)
DOM Node Properties 168493: XML and Web Services (II/2546)
DOM Node Properties 168493: XML and Web Services (II/2546)
DOM Node Methods 168493: XML and Web Services (II/2546)
DOM Node Methods 168493: XML and Web Services (II/2546)
Node Types 168493: XML and Web Services (II/2546)
Node Types 168493: XML and Web Services (II/2546)
DOM NodeList Object • length: return the number of nodes in a nodeList • item: return a specific node in the nodeList • Examples: • xmlDoc.documentElement.childNodes.length • xmlDoc.documentElement.childNodes.item(2) 168493: XML and Web Services (II/2546)
DOM Elements • tagName: return the tag name of a node • getElementsByTagName: return the value of a specified node • getAttribute: return an attribute’s value 168493: XML and Web Services (II/2546)
DOM Attributes • name: return the name of an attribute • Value: return the value of an attribute • Example: for each x in xmlDoc.documentElement.attributes document.write(x.name) document.write(x.value) next 168493: XML and Web Services (II/2546)