1 / 51

XPath

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

darius
Télécharger la présentation

XPath

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XPath A flexible notation for pointing into and navigating around XML documents

  2. Content • What is XPath? • General Expressions • Location Steps and Paths • Abbreviations

  3. What is XPath?

  4. General Expressions

  5. Atomic Values • Numbers: integers, decimals, floats, doubles • Booleans • Strings (Unicode)

  6. Literal Expressions

  7. 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]

  8. Arithmetic Expressions

  9. 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)

  10. Location Steps and Paths

  11. Location paths location step 1/location step 2/… Input: context node or node sequence

  12. Location steps axis :: nodetest [ exp1] [ exp1] …

  13. Axes

  14. child

  15. descendant

  16. parent

  17. ancestor

  18. following

  19. preceding

  20. self

  21. descendant-or-self

  22. ancestor-or-self

  23. following-sibling

  24. preceding-sibling

  25. attribute

  26. Abbreviations

  27. child:: • Abbreviation: (nothing) • Example:/wikimedia/projects/projectfor/child::wikimedia/child::projects/child::project

  28. attribute:: • Abbreviation: @ • Example:/wikimedia/projects/project/@namefor/wikimedia/projects/project/attribute::name

  29. position()=x • Abbreviation: x • Example:/descendant::project[2] for/descendant::project[position()=2]

  30. /descendant-or-self::node()/ • Abbreviation: // • Example://projectfor/descendant-or-self::node()/project

  31. self::node() • Abbreviation: . • Example://edition[. = "de.wikipedia.org"]for//edition[self::node() = "de.wikipedia.org“]

  32. parent::node() • Abbreviation: .. • Example://edition[@language="German"]/../../@namefor//edition[@language="German"]/parent::node()/parent::node()/@name

  33. Node Tests

  34. name

  35. *

  36. node()

  37. text()

  38. comment()

  39. Predicates

  40. Values  Boolean

  41. Example

  42. Order and Conjunction • /descendant[3][1] • /descendant[1][3] • /descendant[position()=1 and position()=3]

  43. Tricky Expressions … are they?!

  44. Tricky Abbreviations • /descendant::edition[1] • //edition[1] • // ≠ /descendant:: • // = /descendant-or-self::node()/

  45. Tricky Predicates • //recipe/ingredient[//ingredient] • //recipe/ingredient[.//ingredient]

  46. Summarizing Examples

  47. Example 1

  48. Example 2

More Related