XPath: Difference between revisions
Jump to navigation
Jump to search
(→Syntax) |
|||
Line 22: | Line 22: | ||
{{External|https://www.baeldung.com/java-xpath}} | {{External|https://www.baeldung.com/java-xpath}} | ||
=Syntax= | =Syntax= | ||
==Example== | |||
<syntaxhighlight lang='xml'> | <syntaxhighlight lang='xml'> | ||
<books> | |||
<book id="1" category="linux"> | |||
<title lang="en">Linux Device Drivers</title> | |||
<year>2003</year> | |||
<author>Jonathan Corbet</author> | |||
<author>Alessandro Rubini</author> | |||
</book> | |||
<book id="2" category="linux"> | |||
<title lang="en">Understanding the Linux Kernel</title> | |||
<year>2005</year> | |||
<author>Daniel P. Bovet</author> | |||
<author>Marco Cesati</author> | |||
</book> | |||
<book id="3" category="novel"> | |||
<title lang="en">A Game of Thrones</title> | |||
<year>2013</year> | |||
<author>George R. R. Martin</author> | |||
</book> | |||
<book id="4" category="novel"> | |||
<title lang="fr">The Little Prince</title> | |||
<year>1990</year> | |||
<author>Antoine de Saint-Exupéry</author> | |||
</book> | |||
</books> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 02:22, 1 July 2021
External
- https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NSXML_Concepts/Articles/QueryingXML.html
- https://www.baeldung.com/linux/evaluate-xpath
Internal
Overview
XPath is a specification language that allows specifying parts of an XML structure. It is part of XSL. An XPath expression can be thought as an address of a part of an XML document.
TODO: https://docs.oracle.com/javase/tutorial/jaxp/xslt/xpath.html
Command Line Tooling
Java Support
Syntax
Example
<books>
<book id="1" category="linux">
<title lang="en">Linux Device Drivers</title>
<year>2003</year>
<author>Jonathan Corbet</author>
<author>Alessandro Rubini</author>
</book>
<book id="2" category="linux">
<title lang="en">Understanding the Linux Kernel</title>
<year>2005</year>
<author>Daniel P. Bovet</author>
<author>Marco Cesati</author>
</book>
<book id="3" category="novel">
<title lang="en">A Game of Thrones</title>
<year>2013</year>
<author>George R. R. Martin</author>
</book>
<book id="4" category="novel">
<title lang="fr">The Little Prince</title>
<year>1990</year>
<author>Antoine de Saint-Exupéry</author>
</book>
</books>
Full Path:
//element-name/element-name[index]/element-name[@attribute-name='value']
Recursive query based on element name:
//element-name[@attribute-name='value']
//element-name[sub-element-expression]