1 / 24

Understanding XML Document Object Model for Efficient Data Manipulation

Learn about the purpose, development, and usage of XML Document Object Model (DOM) with essential interfaces and methods. Explore techniques to add, delete elements, attributes, and manipulate DOM trees effectively for enhanced data handling.

Download Presentation

Understanding XML Document Object Model for Efficient Data Manipulation

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. Beginning XML 4th Edition

  2. Chapter 11: The XML Document Model (DOM)

  3. Chapter 11 Objectives • What is the purpose of the XML Document Object Model? • How the DOM specification was developed at W3C • About important XML DOM interfaces and objects, such as the Node and Document interfaces • How to add and delete elements and attributes from a DOM and manipulate a DOM tree in other ways • How the XML DOM is used "under the covers" in Microsoft InfoPath 2003

  4. What Is an XML Document Object Model For? • One of the possibilities is to read a file from disk. This is a common technique now when dealing with configuration files; user options held in an XML format are easier to deal with than the traditional techniques such as INI files or Registry settings. • A second option is to convert a string representation embedded in the source code. This is popular for examples but not often used in real-life scenarios because of the difficulty in changing the XML when needed. • A third method is to accept a stream piped from another source such as a response from a web service or a database stored procedure.

  5. DOM Document

  6. Interfaces and Objects • Abstract concept • Properties defined are all available • Methods specified are all available

  7. The Document Object Model at the W3C DOM Level 1 www.w3.org/DOM/ DOM Level 2 www.w3.org/TR/DOM-Level-2-Core/ DOM Level 3 www.w3.org/TR/DOM-Level-3-Core/

  8. Two Ways to View DOM Nodes • A hierarchy of node objects • Easy to identify common properties and methods • Document node as root • Descendant nodes are specialized object types • Child node • DocumentType • ProcessingInstructions • Comments We like the second one

  9. Overview of the XML DOM Nodes • Root of the DOM hierarchy is the Document node • Child nodes are: • DocumentType nodes • Element nodes • ProcessingInstruction nodes • Comment nodes Only the element node can have child nodes.

  10. Tools to Run the Examples • The Differences Between Browsers • Microsoft • COM class • Active X Component • JavaScript (Jscript) • Mozilla aka Firefox • alert( )

  11. Try It Out Navigating to the Document Element

  12. Document Element

  13. The Node Object attributes childNodes firstChild lastChild localName namespaceURI nextSibling nodeName nodeType nodeValue ownerDocument parentNode prefix previousSibling

  14. Try It Out Exploring Child Nodes

  15. Methods of the Node Object appendChild(newChild) cloneNode(deep) hasAttributes() hasChildNodes() insertBefore(newChild, refChild) isSupported(feature, version) normalize() removeChild(oldChild) replaceChild(newChild, oldChild)

  16. Try It Out Deleting a NodeAdding New Nodes

  17. The Effect of Text Nodes <Book xml:space="preserve"> <Chapter>This is Chapter 1.</Chapter> <Chapter>This is Chapter 2.</Chapter> <Chapter>This is Chapter 3.</Chapter> </Book> See the IE Result Click Here See the Firefox Result Click Here

  18. The NamedNodeMap Object • getNamedItem(name) • getNamedItemNS(namespaceURI, localName) • item(index) • removeNamedItem(name) • removeNamedItemNS(namespaceURI, localName) • setNamedItem(node) • setNamedItemNS(node) • and • NodeList Object • DOMException Object

  19. Try It Out Adding and Removing AttributesCreating a DOMException

  20. The Document Interface • documentElement • doctype • implementation 3 Interfaces and 14 methods

  21. How the XML DOM Is Used in InfoPath 2007 • XML-based form tool • Using XML DOM in MSXML 6 • Free trial download http://office.microsoft.com/en-us/infopath/default.aspx

  22. InfoPath

More Related