Dom
In DOM, we will represent the programming object of the XML file, called the node (nodes). When Internet Explorer 5 processes a linked XML file and stores it in the DOM, it creates a node for each of the basic components of the XML file. These basic components include elements, attributes, and the processing instruction DOM uses different forms of nodes to represent different forms of XML components. For example, the element is stored in the element node, and the attribute is stored in the attribute node. Table 9-1 lists the most important parts of these node types.
The node Shape node object represents the XML file component node name (NodeName object attribute) node's value (NodeValue object attribute) file (document) File hierarchy root node (representing the entire XML file) #document Null element (elemen T) element element shape name (for example, book) null (any character data that is contained in an element (element), is bit in one or more child text nodes) text (text) is the element, attribute, and text of the entity represented by the parent node of this node. #text the literal attributes (attribute) attributes (and other name-value pairs of the parent XML component, such as the name and value in the processing instruction) property name (such as binding) property value (for example, hardcover) processing instruction (processing instruction) An instruction (XML declaration or custom processing instruction) that handles the object of an instruction (for example, XML) In addition to the contents of the entire processing instruction (for example, Version "1.0") annotation (Comment) annotation #comment The text in the annotation symbol CDATA Section (cdatasection) CDATA section #cdata the content file type in the-section CDATA section (document
Type) file form declares the name of the root element in the DOCTYPE declaration (for example, the inventory) NULL entity (Entity) the Entity Declaration entity name (for example, image) Null (entity value is bit in the Child text node) the label declaration in the label DTD Label name (for example, BMP) > Null (the system literal (notation) of the volume label is bit in the child attribute node named system)
Table 9-1 is used to represent the basic node morphology of different XML file components. Each of these types of nodes is a programming object that provides properties and methods for accessing related components.
You can get the name of each node from the NodeName attribute in the node (detailed in the third column in table 9-1). This name starts with the character #, representing the standard name of the XML component node that is not named in the file. (for example, annotations in an XML file are not named.) Therefore, the DOM will use the standard name #comment. The name of the other node is derived from the name specified in the XML file that corresponds to the component. (for example, an element node that represents a form book element can also be named book.)
You can get the node value for each node from the NodeValue property of the node (listed in table 9-1 in the last column). If the XML component has an associated value (for example, an attribute), the value is stored in the node's node value. If the XML component does not have a node value (for example, an element), the DOM will set the node value to null. Later in this chapter, you will learn more about the various node types listed in Table 9.1.
The DOM constructs the nodes of the XML file into a tree-like hierarchy, reflecting the hierarchy of the XML file itself. The DOM will create a single file node to represent the entire XML file and treat it as the root node of the hierarchy. Note that the logical hierarchy of XML elements contains the entire XML file, the root node in the structure, and only a branch of the hierarchy of the DOM node.
Refer to the XML file example in Listing 9-1. (You can find listing 9-1 in the Dom.xml file of the accompanying book CD.) This file contains XML announcements, annotations, and node elements that contain child elements and attributes.
The following figure shows the hierarchical organization of the nodes that the DOM establishes to render this sample file. For each component in the sample file, the diagram indicates the node shape (for example, files, annotations, and elements) for each component and the name of the node (shown in the following brackets-for example, #document, #comment, and Inventory).
[1] [2] Next page