XQuery 术语
XQuery 术语表
节点
在 XQuery 中,有七种节点:元素、属性、文本、命名空间、处理指令、注释和文档(根)节点。
XML 文档被视为节点树。树的根称为文档节点(或根节点)。
查看以下 XML 文档
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
<title lang="en">哈利波特</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
以上 XML 文档中节点的示例
<bookstore> (根节点)
<author>J K. Rowling</author> (元素节点)
lang="en" (属性节点)
原子值
原子值是没有子节点或父节点的节点。
原子值示例
J K. Rowling
"en"
项
项是原子值或节点。
节点关系
父节点
每个元素和属性都有一个父节点。
在以下示例中; book 元素是 title、author、year 和 price 的父节点
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
子节点
元素节点可以有零个、一个或多个子节点。
在以下示例中; title、author、year 和 price 元素都是 book 元素的子节点
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
同级节点
拥有相同父节点的节点。
在以下示例中; title、author、year 和 price 元素都是同级节点
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
祖先节点
一个节点的父节点、父节点的父节点等。
在以下示例中; title 元素的祖先是 book 元素和 bookstore 元素
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
后代节点
一个节点的子节点、子节点的子节点等。
在以下示例中; bookstore 元素的后代是 book、title、author、year 和 price 元素
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>