Presentation is loading. Please wait.

Presentation is loading. Please wait.

Xpath Examples Edel Sherratt. Llandwp Sports Club Members <?xml-stylesheet type="text/xml" href="members.xsl"?> …

Similar presentations


Presentation on theme: "Xpath Examples Edel Sherratt. Llandwp Sports Club Members <?xml-stylesheet type="text/xml" href="members.xsl"?> …"— Presentation transcript:

1 Xpath Examples Edel Sherratt

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

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::membe r/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() //@*


Download ppt "Xpath Examples Edel Sherratt. Llandwp Sports Club Members <?xml-stylesheet type="text/xml" href="members.xsl"?> …"

Similar presentations


Ads by Google