Skip to content
Search

XPath

lastmod 2018-08-17created 2014-06-095 edits

XPath (XML Path Language) is a W3C standard language that describes how to locate and process items using syntax specified on paths through the structure of Extensible Markup Language documents. It is simpler and more abbreviated than XML notation, and is used in XSL Transformations (XSLT) and the XML Pointer Language (XPointer). XPath uses path expressions to define nodes in an XML document, and has mathematical functions and other extensible expressions.

Example

Example XML document

<?xml version="1.0" encoding="utf-8"?>
<wikimedia>
  <projects>
    <project name="Wikipedia" launch="2001-01-05">
      <editions>
        <edition language="English">en.wikipedia.org</edition>
        <edition language="German">de.wikipedia.org</edition>
        <edition language="French">fr.wikipedia.org</edition>
        <edition language="Polish">pl.wikipedia.org</edition>
      </editions>
    </project>
    <project name="Wiktionary" launch="2002-12-12">
      <editions>
        <edition language="English">en.wiktionary.org</edition>
        <edition language="French">fr.wiktionary.org</edition>
        <edition language="Vietnamese">vi.wiktionary.org</edition>
        <edition language="Turkish">tr.wiktionary.org</edition>
      </editions>
    </project>
  </projects>
</wikimedia>

The following XPath expression

/wikimedia/projects/project/@name

selects the name attribute of all project elements, the following XPath expression

/wikimedia/projects/project/editions/edition[@language="English"]/text()

selects the addresses of all English Wikimedia projects (the text of all edition elements whose language attribute is English), and the following XPath expression

/wikimedia/projects/project[@name="Wikipedia"]/editions/edition/text()

selects the addresses of all Wikipedias (the text of all edition elements under the project element whose name attribute is Wikipedia).

See also

Favorite site