XQuery 用語
XQuery には7種類のノードがあります:要素、属性、テキスト、名前空間、処理命令、コメント、およびドキュメントノード(またはルートノード)です。
XQuery 用語
ノード
XQuery には7種類のノードがあります:要素、属性、テキスト、名前空間、処理命令、コメント、およびドキュメント(ルート)ノードです。XML ドキュメントはノードツリーとして扱われます。ツリーのルートはドキュメントノードまたはルートノードと呼ばれます。
以下の XML ドキュメントを見てください:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
Harry Potter
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<bookstore>
<book>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
上記の XML ドキュメント内のノードの例:
<bookstore>(ドキュメントノード)
<author>J K. Rowling</author>(要素ノード)
lang="en"(属性ノード)
<author>J K. Rowling</author>(要素ノード)
lang="en"(属性ノード)
基本値は親も子も持たないノードです。
基本値の例:
J K. Rowling
"en"
"en"
アイテム
アイテムは基本値またはノードです。
ノード関係
親(Parent)
すべての要素と属性には親があります。
以下の例では、book 要素は title、author、year、price 要素の親です:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
子(Children)
要素ノードはゼロ個、1個、または複数の子を持つことができます。
以下の例では、title、author、year、price 要素はすべて book 要素の子です:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
兄弟(Sibling)
同じ親を持つノード。
以下の例では、title、author、year、price 要素はすべて兄弟です:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
先祖(Ancestor)
あるノードの親、その親の親、など。
以下の例では、title 要素の先祖は book 要素と bookstore 要素です:
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
子孫(Descendant)
あるノードの子、その子の子、など。
以下の例では、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>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>