4. 14.1.1 What is the DOM? The DOM is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents like XML and HTML: A Document Object Model (DOM) is a programming interface that allows programs and programming languages to access and update the content, structure, and style of documents in a standard way. The DOM is separated into 3 different parts / levels: Core DOM - standard model for any structured document XML DOM - standard model for XML documents HTML DOM - standard model for HTML documents The DOM defines the objects and properties of all document elements, and the methods (interface) to access them.
5. 14.1.2 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 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. 14.1.3 Example You can describe the bookstore.xml document as a series of elements and their content. You can also describe the document as a series of objects — after all, each element in the document is an individual object. All these individual objects are part of the DOM for the bookstore.xml document. <bookInfo> <title>The Da Vinci Code</title> <author>Brown, Dan</author> <publisher>Doubleday</publisher> <isbn>0385504209</isbn> </bookInfo> The following piece of the document (for example) includes five different objects
7. 14.1.4 Frankly, My Dear, I Don’t Give a DOM (Cont) A DOM shows how each element relates to the others hierarchically. The DOM identifies each unique object in a document according to its position in the document’s hierarchy. As in any hierarchy, the DOM consists of a fairly complex system of relationships that must be adhered to. siblings, parents, …
8. 14.1.4 Frankly, My Dear, I Don’t Give a DOM (Cont) A processoris an application that makes your documents do something. XML processors create a DOM each time they process an XML document so that the programming code can get and work with the content in the document. Figure 14-1 is a grid view of bookstore.xml in XMLSpy. It illustrates how the DOM for this document might look to an XML processor.
9. 14.1.5 Keeping in touch with the family The terms parent, child, and sibling are all used to describe element relationships. These relationships have to do with how the elements are nested. For example, in the following bit of markup, the street, city, and state elements are nested within (and children of) the address element: <address> <street>1312 Wilshire Blvd</street> <city>Santa Monica</city> <state>California</state> </address>
10. 14.1.6 Understanding DOM structure A tree is a diagramof an XML document’s structure that shows the order of elements and illustrates the relationships between elements in exactly the same way that a family tree illustrates genealogy. A tree is a visual representation of the DOM. XML DOM Tree Example
11. 14.1.6 Understanding DOM structure (Cont) Notice that the tree includes things other than the elements in the document — for example, attributes and element content. The objects included in a DOM are more than just the elements; they’re called nodes when displayed on the DOM tree. Figure 14-2 illustrates some additional types of nodes that a DOM tree can include. There’s not much in any given XML document that you can’t access by using the DOM.
12.
13. The only difference is that the application applies the stylesheet to the XML document.The stylesheet has its own DOM, as does the XML document; the final transformation or display guided by the stylesheet takes information in both DOMs into account.
14. 14.1.6.2 Web browsers and the DOM To display XML documents in Web browsers You actually have to apply an XSLT stylesheet to the XML document — which converts XML to HTML or XHTML. Or you can use an XSL-FO stylesheet with the XML document for display in the browser For example when Internet Explorer 6 displays content using an XSL- FO stylesheet, two processes actually occur Internet Explorer accesses the DOM that’s created when its processor — Microsoft XML (MSXML) — reads and processes both the XML document and the related XSL-FO stylesheet. The browser uses the document and stylesheet together to determine a the final display of the content.
15. 14.2 What Goes In Must Come Out: Processing XML A processor takes the code and makes it do something. A processor may be part of : A simple Web browser (such as Internet Explorer or Mozilla). A whole other kind of program — such as a utility that takes in an XML document, grabs the info it’s carrying, and populates an Oracle database. XML processors and the DOM go hand in hand. All Web browsers have HTML processors built into them, and those that can work with XML also have XML processors built into them. If you create a stylesheet in either XSL or CSS, an XML-enabled browser can also open and process that stylesheet. All XML solutions have processors involved in them Many different processors are available for you to choose among. A program for manipulation — processors are written in a variety of languages.
16. 14.2.1 So many processors, so little time There are many the XML Parsers / Processors , What makes all these processors different from one another? Each processor has four distinct characteristics: The programming language it was written in. Whether or not it validates documents The version of the different specifications (DTD, schema, and so on) that it supports If it was written to accompany a particular software or database application
17. 14.2.1 Which processor is right for you? When you’re trying to pick a processor, you should ask yourself the following questions to help narrow your search: What programming language is the rest of your solution using? Do your documents need to be validated during processing? Which XML versions and standards are you using? Does the application framework or database you’re using have a processor?