1 / 15

Xpath Examples

Xpath Examples. Edel Sherratt. Llandwp Sports Club Members. <?xml version="1.0"?> <?xml- stylesheet type="text/xml" href ="members.xsl"?> <members> … <member> …</member> <member> …</member> … </members>. XPath Data Model. XPath examples to try in BaseX with LlandwpMembers.xml.

eldon
Download Presentation

Xpath Examples

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 Examples Edel Sherratt

  2. Llandwp Sports Club Members <?xml version="1.0"?> <?xml-stylesheet type="text/xml" href="members.xsl"?> <members> … <member> …</member> <member> …</member> … </members>

  3. XPath Data Model

  4. XPath examples to try in BaseX with LlandwpMembers.xml • /child::members • /descendant::member • /descendant::member[@number="17"] • /descendant::sport[string()="soccer"] • /descendant::sport[string()="soccer"]/ancestor::member • /descendant::com_role/ancestor::member • /descendant::sport[string()="squash"]/ancestor::member/name

  5. Structure of an XPath location path • /step/step/step … • step/step … • Each step in the location path has three parts • axis • nodetest • predicates • axis::nodetest[predicate][predicate]…

  6. What each step means • Starting from a context (you are here) • Specify an axis: parent, child, ancestor, descendant, attribute … • Filter the axis to get the kind of nodes you want (e.g., name an element) • Then filter again using expressions to get the precise nodes you want • do the same until all the steps are complete

  7. More examples to try in BaseX with LlandwpMembers.xml • /descendant::renewal_due • /descendant::renewal_due/ancestor::member • /descendant::sport[string()="soccer"]/ancestor::member • /descendant::sport[string()="soccer"]/ancestor::member/child::name • /descendant::team[string()="Soccer A"]/ancestor::member/child::name • /descendant::member/attribute::number

  8. More about node tests • A name returns nodes with that name • node() selects all nodes • processing-instruction() returns processing instructions • text() selects character data nodes • comment() selects comment nodes

  9. Examples to try with LlandwpMembers.xml • /child::processing-instruction() • /child::members • /child::node() • /descendant::member • /descendant::member/descendant::text() • /descendant::sport • /descendant::sport/child::text()

  10. Some shortcuts • child is the default axis, so /members is equivalent to /child::members • // is shorthand for /descendant-or-self::node(), so //name is equivalent to /descendant-or-self::node()/name • . is shorthand for self::node() • .. is shorthand for parent::node()

  11. More queries to try • //sport • //sport/.. • //sport/../.. • //sport/../../name

  12. And yet more … • /processing-instruction() • /members • /node() • //member//text() • //name • //name/text()

  13. And more • //renewal_due • //renewal_due/ancestor::member • //sport[string()="soccer"]/ancestor::member • //sport[string()="soccer"]/ancestor::member/name • //team[string()="Soccer A"]/ancestor::member/name

  14. Wildcards in node tests • node() matches any kind of node • * matches any element • @* matches any attribute

  15. Final set of examples • //team[string()="Soccer A"]/ancestor::member/@number • //team[string()="Soccer A"]/ancestor::member/@* • /* • /node() • //@*

More Related