XPath

XPath (XML Path Language) is a terse (non-XML) syntax for addressing portions of an XML document.

Originally motivated by a desire to provide a common syntax and behavior model between XPointer and XSL, XPath has rapidly been adopted by developers as a small query language.

Notation

The notation is compact, suitable for expressing within XML attributes. It assumes a simple URI like syntax. A typical XPath expression is a Location Path consisting of a string of element or attribute qualifiers separated by forward slashes ("/"), similar in appearance to a file system path. XPath also allows built-in functions, filters, bound variable access, and axis specifiers.

Location Paths are divided into Steps, each of which has three components:

  • Axis Specifier
  • Node Test
  • Predicate

An Axis Specifier indicates the kind of information which will be selected. For instance, child:: is the unabbreviated axis specifier for element children. For many XPath expressions, the axis specifier is omitted allowing it to default to child::. A common abbreviated axis specifier is a commercial "at" sign ("@"), which represents attributes.

A Node Test limits the specific elements or attributes which will be addressed. A common form of node test is a name test which is the name of an element or an attribute.

Predicates are used to filter out, or exclude, certain nodes on the basis of more complex expressions. Predicates are introduced using a square-bracket ("[", "]") syntax.

Functionality and usage

XPath further defines a library of standard functions for working with strings, numbers and Boolean expressions, as well as supporting a number of utility operators. The following is by no means an exhaustive list but is nevertheless illustrative of the range of functionalities and operators.

  • Wildcards (*) may be used to select elements in an XML which may be unknown.
  • The use of square brackets [] may be used to qualify a particular element.
  • Multiple paths are supported by use of the | operator.
  • Attributes are defined by the @ prefix.
  • Numerical operations supported include: addition (+), subtraction (-), multiplication (*), division (div), and modulus (mod).
  • Equality tests can be performed by use of the like (=) and not like (!=) operators.
  • Example Functions include
    • Nodeset functions:
      • count() - counts the items in a nodeset
      • id () - selects elements by their id
      • name() - returns a node's name
    • String functions:
      • normalize-space() - strips trailing and leading whitespace
      • substring()
      • string-length()

Examples

An exhaustive set of examples is beyond the scope of this article. Some typical XPath expressions which might be used in an XSL context are:

  • The Root element: /*
  • All elements everywhere (implementations of this expression can be very slow): //*
  • All Top Level Elements (children of Root): /*/*
  • The fifth child element (of the current node as defined by the context of the expression) named "FOOB": FOOB[5]
  • All child elements (of the current node as defined by the context of the expression) FOOB whose BAZ attributes are "untrue": FOOB[ @BAZ = "untrue" ]

See also

External link

es:XPath fr:XPath he:XPath nl:XPath ru:XPath sv:XPath zh:XPath

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools