1 / 23

Understanding XML and XML DOM: A Comprehensive Guide

Learn about XML, its structure, and its use in defining and encoding documents. Explore the XML DOM, a standard programming interface for accessing and manipulating XML documents. Understand the hierarchical relationship of XML nodes and how to parse XML using XML DOM.

Download Presentation

Understanding XML and XML DOM: A Comprehensive Guide

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML is…

  2. XML is… • defined as Extensible Markup Language (XML) is a set of rules for encoding documents • Defines structure and data

  3. XML is… <bookstore>  <book category="cooking">    <title lang="en">Everyday Italian</title>    <author>Giada De Laurentiis</author>    <year>2005</year>    <price>30.00</price>  </book> </bookstore>

  4. XML DOM • A W3C standard that defines a standard way for accessing and manipulating XML documents • DOM presents an XML document as a tree-structure

  5. XML DOM • A standard programming interface for XML that is platform- and language-independent • The XML DOM defines the objects and properties of all XML elements, and the methods (interface) to access them. • In other words: The XML DOM is a standard for how to get, change, add, or delete XML elements.

  6. XML DOM Nodes • According 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

  7. XML Node Example <bookstore>  <book category="cooking">    <title lang="en">Everyday Italian</title>    <author>Giada De Laurentiis</author>    <year>2005</year>    <price>30.00</price>  </book> </bookstore> root

  8. XML Node Example <bookstore>  <book category="cooking">    <title lang="en">Everyday Italian</title>    <author>Giada De Laurentiis</author>    <year>2005</year>    <price>30.00</price>  </book> </bookstore> Book node

  9. XML Node Example <bookstore>  <book category="cooking">    <title lang="en">Everyday Italian</title>    <author>Giada De Laurentiis</author>    <year>2005</year>    <price>30.00</price>  </book> </bookstore> Book node contains four other nodes

  10. XML DOM Node Tree • The XML DOM views an XML document as a tree structure called a node-tree • All the nodes in the tree have a relationship to each other and can be accessed through the tree • The node tree shows the set of nodes, and the connections between them. The tree starts at the root node and branches out to the text nodes at the lowest level of the tree

  11. XML DOM Node Tree

  12. XML Parent/Child Relationship • Nodes in the node tree have a hierarchical relationship to each other • The terms parent, child, and sibling are used to describe the relationships. For example, Parent nodes have children

  13. XML Parent/Child Relationship • Children on the same level are called siblings (brothers or sisters) which are nodes with the same parent • In a node tree, the top node is called the root only one root can exist in an XML file. • Every node, except the root, has exactly one parent node

  14. XML Parent/Child Relationship

  15. Document Object Model <bookstore>  <book category="cooking">    <title lang="en">Everyday Italian</title>    <author>Giada De Laurentiis</author>    <year>2005</year>    <price>30.00</price>  </book> </bookstore> • In the XML above, the <title> element is the first child of the <book> element, and the <price> element is the last child of the <book> element • Furthermore, the <book> element is the parent node of the <title>, <author>, <year>, and <price> elements

  16. XML DOM Parsing • Most browsers have a built-in XML parser to read and manipulate XML • The parser converts XML into a JavaScript accessible object • The XML DOM contains methods (functions) to traverse XML trees, access, insert, and delete nodes

  17. XML DOM Parsing • However, before an XML document can be accessed and manipulated, it must be loaded into an XML DOM object • The parser reads XML into memory* and converts it into an XML DOM object that can be accessed with JavaScript * you must clear the browser cache to update the XML file

  18. XMLHTTPRequest • Create an XMLHTTP object • Open the XMLHTTP object • Send an XML HTTP request to the server

  19. Warning!

  20. Warning! Danger, Will Robinson, Danger!

  21. XMLDOM - Warning Danger, Will Robinson, Danger!

  22. Microsoft.XMLDOM xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

More Related