↑
Main Page
DOM document
A document is made up of a hierarchy of any number of these nodes. Consider the following XML code:
<?xml version=”1.0”?>
<employees>
<!-- only employee -->
<employee>
<name>Michael Smith</name>
<position>Software Engineer</position>
<comments><![CDATA[
His birthday is on 8/14/68.
]]></comments>
</employee>””
</employees>
This code can be represented in a DOM document as displayed in Figure 6-1.
Figure 6-1
In Figure 6-1, each rectangle represents a node in the DOM document tree, with the bold text indicating
the node type and the nonbold text indicating the content of that node.
Both the comment and
<employee/>
nodes are considered to be
child nodes
of
<employees/>
because
they fall immediately underneath it in the tree. Likewise,
<employees/>
is considered the parent node
of the comment and
<employee/>
nodes.
Similarly,
<name/>
,
<position/>
, and
<comments/>
are all considered child nodes of
<employee/>
and are also considered
siblings
of each other because they exist at the same level of the DOM tree and
have the same parent node.
Document
Document
Element
Element employees
Comment
Comment only
employee
Element
Element employee
Element
Element position
Element
Element comments
Element
Element name
Text
Text Software Engineer CDataSection
CDataSection
Text
Text Michael Smith
Text
Text His bir thday is on 8/14/68.
164
Chapter 6
09_579088 ch06.qxd 3/28/05 11:37 AM Page 164
Free JavaScript Editor
Ajax Editor
©
→