[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
XML structures data into a rather small number of different constructs, most notably elements and attributes. The XML Path Language (XPath) defines a way how to select parts of XML documents, so that they can be used for further processing. XPath's primary use in in XSL Transformations (XSLT) and XQuery, but other XML technologies use it as well, e.g. XSD. XPath is a compact language with a syntax that resembles path expressions well-known from file systems. These path expressions, however, are generalized and therefore more powerful than the rather simple path expressions in file systems. Because of its use in different XML technologies, XPath is one of the most important XML core technologies.
ü
/ü
→ ü
)//img[not(@alt)]
→ select all images which have no alt
attributecount(//img)
→ return the number of images/descendant::img[3]/@src
→ return the third image's src
URIstarts-with(/html/@lang, 'en')
→ test whether the document's language is english/
, like path names in file systemsFile System Path: | / |
usr |
/ |
local |
/ |
apache |
/ |
bin |
/ |
---|---|---|---|---|---|---|---|---|---|
# Selected Nodes: | 1 | → 1 | → | 1 | → | 1 | → | 1 |
XPath: | / |
html |
/ |
body |
/ |
table |
/ |
thead |
/ |
tr |
---|---|---|---|---|---|---|---|---|---|---|
# Selected Nodes: | 1 | → 1 | → | 1 | → | 6 | → | 4 | → | 12 |
/html/head/title
/html/head/*
text()
comment()
node()
processing-instruction()
processing-instruction("xml-stylesheet")
.
and ..
are clever directory shortcutsfind
)child
descendant::a
xmlns
) are invisible/
preceding::p[@class="warning"]
)::
(no axis uses the default axis child
)[]
child::
can be omitted (default axis)attribute::
can be written as @
.
is an abbreviation for self::node()
..
is an abbreviation for parent::node()
//
is an abbreviation for /descendant-or-self::node()/
position()
function (/descendant::a[5]
)//img[not(@alt)]
count(//img)
/descendant::img[3]/@src
starts-with(/html/@lang, 'en')
NaN
)//a[starts-with(@href, https)]
)boolean, contains, false, lang, not, starts-with, true
ceiling, count, floor, last, number, position, round, string-length, sum
concat, local-name, name, namespace-uri, normalize-space, string, substring, substring-after, substring-before, translate
id
//a[substring(@href,string-length(@href)-2)='pdf']
Wu Problemnumber (distinct authors with the last name
Wu)? 252