Sunteți pe pagina 1din 2

XPath Axes

http://www.w3schools.com/xpath/xpath_axes.asp

TRANSLATE

HOME

HTML

CSS

XML

JAVASCRIPT

ASP

PHP

SQL

MORE...

REFERENCES | EXAMPLES | FORUM | ABOUT

XPath Tutorial
XPath HOME XPath Intro XPath Nodes XPath Syntax XPath Axes XPath Operators XPath Examples XPath Summary

XPath Axes
Previous Next Chapter

WEB HOSTING

The XML Example Document


We will use the following XML document in the examples below.

WEB BUILDING

W3SCHOOLS EXAMS

XPath Reference
XPath Functions

<?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore>

Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP W3SCHOOLS BOOKS New Books: HTML, CSS JavaScript, and Ajax STATISTICS Browser Statistics Browser OS Browser Display SHARE THIS PAGE Share with

XPath Axes
An axis defines a node-set relative to the current node. AxisName ancestor ancestor-or-self attribute child descendant descendant-or-self following following-sibling namespace parent preceding Result Selects all ancestors (parent, grandparent, etc.) of the current node Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself Selects all attributes of the current node Selects all children of the current node Selects all descendants (children, grandchildren, etc.) of the current node Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself Selects everything in the document after the closing tag of the current node Selects all siblings after the current node Selects all namespace nodes of the current node Selects the parent of the current node Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes Selects all siblings before the current node Selects the current node

preceding-sibling self

Location Path Expression


A location path can be absolute or relative. An absolute location path starts with a slash ( / ) and a relative location path does not. In both cases the location path consists of one or more steps, each separated by a slash:

An absolute location path: /step/step/... A relative location path: step/step/...


Each step is evaluated against the nodes in the current node-set. A step consists of: an axis (defines the tree-relationship between the selected nodes and the current node)

1 sur 2

10/07/2012 08:25

XPath Axes

http://www.w3schools.com/xpath/xpath_axes.asp

a node-test (identifies a node within an axis) zero or more predicates (to further refine the selected node-set) The syntax for a location step is:

axisname::nodetest[predicate]

Examples
Example child::book attribute::lang child::* attribute::* child::text() child::node() descendant::book ancestor::book ancestor-or-self::book child::*/child::price Result Selects all book nodes that are children of the current node Selects the lang attribute of the current node Selects all element children of the current node Selects all attributes of the current node Selects all text node children of the current node Selects all children of the current node Selects all book descendants of the current node Selects all book ancestors of the current node Selects all book ancestors of the current node - and the current as well if it is a book node Selects all price grandchildren of the current node

Previous

Next Chapter
REPORT ERROR | HOME | TOP | PRINT | FORUM | ABOUT

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2012 by Refsnes Data. All Rights Reserved.

2 sur 2

10/07/2012 08:25

S-ar putea să vă placă și