Download presentation
Presentation is loading. Please wait.
Published byHollie Short Modified over 8 years ago
1
Parsing with DOM using MSXML Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University
2
168493: XML and Web Services (II/2546) 2 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
3
168493: XML and Web Services (II/2546) 3 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
4
168493: XML and Web Services (II/2546) 4 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
5
168493: XML and Web Services (II/2546) 5 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
6
168493: XML and Web Services (II/2546) 6 Creating an XML Document Object Javascript var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") VBScript set xmlDoc = CreateObject("Microsoft.XMLDOM")
7
168493: XML and Web Services (II/2546) 7 Loading an XML File var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load(“cdcatalog.xml") //....... processing the document goes here
8
168493: XML and Web Services (II/2546) 8 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
9
168493: XML and Web Services (II/2546) 9 DOM Node Properties PropertyDescription attributesReturns all attributes childNodesReturns a NodeList containing all the child nodes parentNodeReturns the parent node firstChildReturns the first child node for this node
10
168493: XML and Web Services (II/2546) 10 DOM Node Properties PropertyDescription firstChildReturns the first child node lastChildReturns the last child node nextSiblingReturns the next sibling node previousSiblingReturns the previous sibling node
11
168493: XML and Web Services (II/2546) 11 DOM Node Properties PropertyDescription nodeTypeReturns the nodeType as a number nodeValueReturns the value of this node ownerDocumentReturns the root node of the document nodeNameReturns the nodeName
12
168493: XML and Web Services (II/2546) 12 DOM Node Methods MethodDescription appendChild (newChild) Appends the node newChild at the end of the child nodees hasChildNodes () Returns true if this node has any child nodes
13
168493: XML and Web Services (II/2546) 13 DOM Node Methods MethodDescription insertBefore (newNode, refNode) Inserts a new node, newNode, before the existing node refNode removeChild (nodeName) Removes the specified node, nodeName replaceChild (newNode, oldNode) Replaces the oldNode, with the newNode
14
168493: XML and Web Services (II/2546) 14 Node Types NodeTypeNamed Constants 1ELEMENT_NODE 2ATTRIBUTE_NODE 3TEXT_NODE 4CDATA_SECTION_NODE 5ENTITY_REFERENCE_NODE 6ENITY_NODE
15
168493: XML and Web Services (II/2546) 15 Node Types NodeTypeNamed Constants 7PROCESSING_INSTRUCTION_N ODE 8COMMENT_NODE 9DOCUMENT_NODE 10DOCUMENT_TYPE_NODE 11DOCUMENT_FRAGMENT_NODE 12NOTATION_NODE
16
168493: XML and Web Services (II/2546) 16 DOM NodeList Object length: return the number of nodes in a nodeList item: return a specific node in the nodeList Examples: xmlDoc.documentElement.childNodes.leng th xmlDoc.documentElement.childNodes.item (2)
17
168493: XML and Web Services (II/2546) 17 DOM Elements tagName: return the tag name of a node getElementsByTagName: return the value of a specified node getAttribute: return an attribute’s value
18
168493: XML and Web Services (II/2546) 18 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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.