1 / 13

XML Path Language

XML Path Language. Andy Clark. Overview. Syntax for selecting nodes in an XML document Location paths and expressions Location paths similar to UNIX paths e.g. /usr/local/bin Result of expression can be Set of nodes (“node-set”) Boolean Number String. Location Paths.

cedric
Download Presentation

XML Path Language

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. XML Path Language Andy Clark 17 Apr 2002

  2. Overview • Syntax for selecting nodes in an XML document • Location paths and expressions • Location paths similar to UNIX paths • e.g. /usr/local/bin • Result of expression can be • Set of nodes (“node-set”) • Boolean • Number • String

  3. Location Paths • Comprised of “steps” • Relative to context node • Each step has three parts • Axis • e.g. parent::, attribute::, child::, descendent::, etc… • Node test • e.g. foo, bar, html:body, etc… • Zero or more predicates • e.g. [1], [foo/bar], [text()=“Andy”], [not(position()=last())], etc…

  4. Axes • Full list • ancestor::, ancestor-or-self:: • attribute:: • child::, descendent::, descendent-or-self:: • following::, following-sibling:: • namespace:: • parent:: • preceding::, preceding-sibling:: • self::

  5. Node Tests • Full list • Name test • e.g. *, qname, etc… • Node type • e.g. node(), text(), etc… • Processing instruction test • e.g. processing-instruction(“xml-stylesheet”)

  6. Predicates • Expressions • Location path • Union of location paths • Variable references • e.g. $name, etc… • String and number literals • e.g. “Andy”, 42, etc… • Functions • e.g. text(), position(), substring(), etc…

  7. Functions • Node-set functions • e.g. position(), last(), local-name(), etc… • String functions • e.g. string(), contains(), substring(), etc… • Boolean functions • e.g. boolean(), not(), etc… • Number functions • e.g. number(), sum(), round(), etc…

  8. Location Path Abbreviated Syntax • Common location paths have short form • self::node() . • parent::node() .. • attribute::bar @bar • child::foo foo • /descendent::foo //foo • descendent::foo .//foo

  9. Path / foo foo/bar foo//bar foo[bar] @baz . .. * @* Selects Root element Element "foo" Child element "bar" of element "foo" Element "bar" descendent of element "foo" Element "foo" contains child "bar" Attribute "baz" This node Parent node Any element Any attribute Basic Examples

  10. More Complex Sample (1 of 2) • Path: • /book/chapter[3]/section[subsection][2] • Selects: • The second section that contains a subsection in the third chapter of the book • In pseudo-SQL: • FROM note root SELECT element “book”, element “chapter” WHERE (position = 3), element “section” WHERE (contains element “subsection” AND position = 2);

  11. More Complex Sample (2 of 2) • Path: • * [ not( preceding-sibling::* [ name() = name( current() ) ] ) ] • Selects: • The set of children elements with unique names • In pseudo-SQL: • FROM node current SELECT element any WHERE ( not( SELECT element any on axis preceding-sibling WHERE (element name = SELECT node current name) ) );

  12. Useful Links • XPath 1.0 Specification • http://www.w3.org/TR/xpath • XSLT 1.0 Specification • http://www.w3.org/TR/xslt

  13. XML Path Language Andy Clark

More Related