Java-xml-java-xpath-parser
提供:Dev Guides
Java XPathパーサー-概要
XPathは、World Wide Web Consortium(W3C)の公式勧告です。 XMLファイル内の情報を検索する言語を定義します。 XMLドキュメントの要素と属性をトラバースするために使用されます。 XPathは、XMLドキュメントから関連情報を照会するために使用できるさまざまなタイプの式を提供します。
XPathとは何ですか?
- 構造の定義-XPathは、要素、属性、テキスト、名前空間、処理命令、コメント、ドキュメントノードなどのXMLドキュメントの部分を定義します。
- Path Expressions -XPathは、XMLドキュメントの選択ノードまたはノードのリストなどの強力なパス式を提供します。
- 標準関数-XPathは、文字列値、数値、日付と時刻の比較、ノードとQNameの操作、シーケンス操作、ブール値などの操作のための標準関数の豊富なライブラリを提供します。
- * XSLTの主要部分*-XPathはXSLT標準の主要な要素の1つであり、XSLTドキュメントを操作するにはXPathの十分な知識が必要です。
- * W3C勧告*-XPathはWorld Wide Web Consortium(W3C)の公式勧告です。
XPath式
XPathはパス式を使用して、XMLドキュメントからノードまたはノードのリストを選択します。 以下は、XMLドキュメントから任意のノード/ノードのリストを選択するための便利なパスと式のリストです。
Sr.No. | Expression & Description |
---|---|
1 |
node-name 指定された名前「nodename」を持つすべてのノードを選択します |
2 |
/ ルートノードから選択を開始 |
3 |
// // 選択は、選択に一致する現在のノードから開始されます |
4 |
. 現在のノードを選択します |
5 |
.. .. 現在のノードの親を選択します |
6 |
@ 属性を選択します |
7 |
student 例-「student」という名前のすべてのノードを選択します |
8 |
class/student 例-クラスの子であるすべての学生要素を選択する |
9 |
//student ドキュメント内のどこにいても、すべての学生要素を選択します |
述語
述語は、特定のノードまたは特定の値を含むノードを見つけるために使用され、[…]を使用して定義されます。
Expression | Result |
---|---|
/class/student[1] | Selects the first student element that is the child of the class element. |
/class/student[last()] | Selects the last student element that is the child of the class element. |
/class/student[last()-1] | Selects the last but one student element that is the child of the class element. |
//student[@rollno = '493'] | Selects all the student elements that have an attribute named rollno with a value of '493' |