XML Document Object Model (DOM)


Published on

XML Document Object Model (DOM) is a standard for accessing and navigating XML code. All structured documents have a DOM system. The DOM simply defines the objects and properties in code, so parsers can identify and understand the individual parts. The DOM presents an XML document as a tree-structure. Knowing the XML DOM is a must for anyone working with XML.

Published in: Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

XML Document Object Model (DOM)

  1. 1. XML DOM Prepared by: Pawan Dhawan Software Engineer Jan -30-2012BOSS Webtech Private Limited www.bosswebtech.com
  2. 2. Points we will covered• What is XML DOM .• Its structure.• Its advantages and disadvantages• Its uses.
  3. 3. WHAT IS DOM ?• DOM is the Document Object Model.• The DOM is a W3C (World Wide Web Consortium) standard.• The DOM defines a standard for accessing documents like XML and HTML:• DOM is memory-based, this making it traversable and editable.• DOM is not language-specific, nor is it platform-specific.
  4. 4. What is the XML DOM?The XML DOM is: • A standard object model for XML • A standard programming interface for XML • Platform- and language-independent • A W3C standard
  5. 5. DOM NodesAccording to the DOM, everything in an XML document is a node.The DOM says:• The entire document is a document node• Every XML element is an element node• The text in the XML elements are text nodes• Every attribute is an attribute node• Comments are comment nodes
  6. 6. DOM Example<?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="web" cover="paperback"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore>
  7. 7. The XML DOM Node Tree
  8. 8. XML DOM PropertiesThese are some typical DOM properties:• x.nodeName - the name of x• x.nodeValue - the value of x• x.parentNode - the parent node of x• x.childNodes - the child nodes of x• x.attributes - the attributes nodes of xNote: In the list above, x is a node object.
  9. 9. XML DOM Methods• x.getElementsByTagName(name) - get all elements with a specified tag name• x.appendChild(node) - insert a child node to x• x.removeChild(node) - remove a child node from xNote: In the list above, x is a node object.
  10. 10. Exampletxt=xmlDoc.getElementsByTagName("title")[0].c hildNodes[0].nodeValue• xmlDoc - the XML DOM object .• getElementsByTagName("title")[0] - the first <title> element• childNodes[0] - the first child of the <title> element (the text node)• nodeValue - the value of the node (the text itself)
  11. 11. Traversing the Node Tree<html> <head> <script type="text/javascript" src="loadxmlstring.js"></script> </head> <body> <script type="text/javascript"> text="<book>"; text=text+"<title>Everyday Italian</title>"; text=text+"<author>Giada De Laurentiis</author>"; text=text+"<year>2005</year>"; text=text+"</book>"; xmlDoc=loadXMLString(text); // documentElement always represents the root node x=xmlDoc.documentElement.childNodes; for (i=0;i<x.length;i++) { document.write(x[i].nodeName); document.write(": "); document.write(x[i].childNodes[0].nodeValue); document.write("<br />"); } </script> </body></html>
  12. 12. Out Puttitle: Everyday Italianauthor: Giada De Laurentiisyear: 2005
  13. 13. Advantages of XML DOM• XML structure is traversable. Each node can be randomly accessed (one or more times) by traversing the tree.• XML structure is modifiable. Since the XML structure is resident in memory, values can be added, changed, and removed.• The DOM standard is maintained by the World Wide Web Consortium.
  14. 14. Disadvantages of XML DOM• Resource intensive Since the XML structure is resident in memory, the larger the XML structure is, the more memory it will consume.• Relative speed In comparison to SAX, DOM can be much slower due to its resource usage/ needs.
  15. 15. Uses of XML DOM• The XML DOM defines a standard way for accessing and manipulating XML documents.• The DOM presents an XML document as a tree-structure.• Knowing the XML DOM makes working easier with XML.
  16. 16. ThankYou!!
  17. 17. About BOSS Webtecho BOSS Webtech is a process oriented design house specializing in web design, web development, backend web programming, mobile application development and other web and mobile related design and support services.o Recently launched BizPlus – Mobile based survey software. Check it more here http://bizplusonline.com/o More products here http://www.bosswebtech.com/products/products.html Contact BOSS Webtecho Call 831-998-9121 at US EST/CST/MST/PST Zone or email info@bosswebtech.com