• var rootNode = xml.documentElement; var alsoRootNode = xml.childNodes.item(0); var element1 = xml.documentElement.childNodes.item(0);
  • var element3 = xml.childNodes.item(0).childNodes.item(2); Figure 5.2
  • Everything Is a Node (Well, Almost Everything)
  • Figure 5.3: DOM Class hierarchy. Node
  • Microsoft Word Applied xml a toolkit for Programmers Wiley doc




    Download 2,96 Mb.
    Pdf ko'rish
    bet106/131
    Sana14.05.2024
    Hajmi2,96 Mb.
    #232039
    1   ...   102   103   104   105   106   107   108   109   ...   131
    Bog'liq
    Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers







    Moreover, understanding the childNodes property is also necessary. The childNodes 
    property is a NodeList node that allows the programmer access to a node’s children. The 
    following script shows how a programmer would use the childNodes collection to gain 
    access to the root element and the children of the root element. Figure 5.2 shows what 
    the DOM exposes and can help follow the script below.

    Figure 5.2:
    DOM representation of above XML document.
    There also exists an attributes property that points to a NamedNodeMap node, which is 
    used to hold a collection of Attribute nodes.
    Everything Is a Node (Well, Almost Everything)
    The chart in Figure 5.3 is not to be confused with Figures 4.13 through 4.19 (The Big 
    Picture). Figure 5.3 depicts the class inheritance. In other words, all classes that have a 
    parent (for example, node is the parent of Element) get all the properties and methods 
    that the parent class has. Figures 4.13 through 4.19, on the other hand, show how the 
    DOM exposes these various nodes. Note that in these figures, node is not found 
    anywhere. Node is used only to derive other classes and is not directly exposed.
    Figure 5.3:
    DOM Class hierarchy.
    Node
    Parent
    : None
    Almost all the nodes described in the 
    preceding chapter
    are derived, either directly or 
    indirectly, from a base class called Node. The exceptions are the NodeList and 
    NamedNodeMap nodes, which don’t have a base class. A class that is derived from 
    another class (referred to as the base class) inherits all the methods and properties of the 
    base class. For example, the Node class defines the method childNodes, which every 
    class derived from Node can use without redefining childNodes. Even though most of the 
    nodes are derived from Node, a Node cannot exist on its own; only the specialized nodes 
    can be created.
    A description of the properties and methods that are available to all classes (except 
    NodeList and NamedNodeMap) is presented in the following section.


    - 117 -

    Download 2,96 Mb.
    1   ...   102   103   104   105   106   107   108   109   ...   131




    Download 2,96 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Microsoft Word Applied xml a toolkit for Programmers Wiley doc

    Download 2,96 Mb.
    Pdf ko'rish