510 likes | 700 Views
XPath. A flexible notation for pointing into and navigating around XML documents. Content. What is XPath? General Expressions Location Steps and Paths Abbreviations. What is XPath?. General Expressions. Atomic Values. Numbers: integers, decimals, floats, doubles Booleans
E N D
XPath A flexible notation for pointing into and navigating around XML documents
Content • What is XPath? • General Expressions • Location Steps and Paths • Abbreviations
Atomic Values • Numbers: integers, decimals, floats, doubles • Booleans • Strings (Unicode)
Comments • (: this is a comment :) • /descendant::(: this is also a comment :)text()[18] • /descendant::text((: this too :))[18] • /descendant::text()[18(: and this :)] • (: btw, (: nesting is allowed :) :) • WRONG: /descendant::text()[1(: not a comment :)8] • WRONG: /descendant::te(: not a comment :)xt()[18]
Sequence Expressions • exp1, exp2, …, expn • (1, (2, 3, 4), ((5)), (), (((6, 7), 8), 9)) • 1, 2, 3, 4, 5, 6, 7, 8, 9 • exp1to exp2 (e.g. 1 to 9)
Location paths location step 1/location step 2/… Input: context node or node sequence
Location steps axis :: nodetest [ exp1] [ exp1] …
child:: • Abbreviation: (nothing) • Example:/wikimedia/projects/projectfor/child::wikimedia/child::projects/child::project
attribute:: • Abbreviation: @ • Example:/wikimedia/projects/project/@namefor/wikimedia/projects/project/attribute::name
position()=x • Abbreviation: x • Example:/descendant::project[2] for/descendant::project[position()=2]
/descendant-or-self::node()/ • Abbreviation: // • Example://projectfor/descendant-or-self::node()/project
self::node() • Abbreviation: . • Example://edition[. = "de.wikipedia.org"]for//edition[self::node() = "de.wikipedia.org“]
parent::node() • Abbreviation: .. • Example://edition[@language="German"]/../../@namefor//edition[@language="German"]/parent::node()/parent::node()/@name
Order and Conjunction • /descendant[3][1] • /descendant[1][3] • /descendant[position()=1 and position()=3]
Tricky Expressions … are they?!
Tricky Abbreviations • /descendant::edition[1] • //edition[1] • // ≠ /descendant:: • // = /descendant-or-self::node()/
Tricky Predicates • //recipe/ingredient[//ingredient] • //recipe/ingredient[.//ingredient]