Dom 简明教程
XML DOM - Node Tree
在本章中,我们将学习 XML DOM 节点树。在 XML 文档中,信息以分层结构维护;此分层结构称为节点树。这种层次结构允许开发人员在树中四处导航以查找特定信息,从而允许访问节点。然后可以更新这些节点的内容。
In this chapter, we will study about the XML DOM Node Tree. In an XML document, the information is maintained in hierarchical structure; this hierarchical structure is referred to as the Node Tree. This hierarchy allows a developer to navigate around the tree looking for specific information, thus nodes are allowed to access. The content of these nodes can then be updated.
节点树的结构从根元素开始,一直延伸到最低级别的子元素。
The structure of the node tree begins with the root element and spreads out to the child elements till the lowest level.
Example
以下示例演示了一个简单的 XML 文档,其节点树结构如下所示 −
Following example demonstrates a simple XML document, whose node tree is structure is shown in the diagram below −
<?xml version = "1.0"?>
<Company>
<Employee category = "Technical">
<FirstName>Tanmay</FirstName>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
</Employee>
<Employee category = "Non-Technical">
<FirstName>Taniya</FirstName>
<LastName>Mishra</LastName>
<ContactNo>1234667898</ContactNo>
</Employee>
</Company>
正如上面看到的示例,其图片表示(其 DOM)如下所示 −
As can be seen in the above example whose pictorial representation (of its DOM) is as shown below −
-
The topmost node of a tree is called the root. The root node is <Company> which in turn contains the two nodes of <Employee>. These nodes are referred to as child nodes.
-
The child node <Employee> of root node <Company>, in turn consists of its own child node (<FirstName>, <LastName>, <ContactNo>).
-
The two child nodes, <Employee> have attribute values Technical and Non-Technical, are referred as attribute nodes.
-
The text within every node is called the text node.