xpath学习中

来源:互联网 发布:淘宝卖家页面 编辑:程序博客网 时间:2024/05/29 15:13
XPath
xpath model
1. XPath
    XPath is a language for finding information in xml documents. XPath is used to navigate through elements and attributes in an xml document.
    XPath is a major element in W3C's standard XSLT.  And XQuery and XPointer are both built on XPath expressions. XQuery 1.0 and XPath 2.0 share the same data model and support the same functions.
    XPath contains a library of standard functions.

2. XPath Expressions
    XPath use path expressions to select a node or a set of nodes. these expressions are very like expressions of file system.
3. XPath standard functions.
    XPath includes over 100 built-in functions. They are functions for string values, numeric values , date and time comparison, name and QName manipulation, sequence manipulation, Boolean values, and more.

XPath terminology
 
In XPath there are several kinds of elements: nodes, attributes, text, namespace,  processing-instruction, comment and document node.

Nodes

    XML doc are treated  as tree of nodes.  The root of the tree is called the root node or document node.

XPath Syntax
    Mostly useful path expressions
    nodename      Select all child nodes of the node.
    /                        Select from the root.
    //                        Select the nodes from the documents that match the selection nomatter where they are.
    .                        Select the current node.
    ..                        Select the parent node.
    @                     Select the attributes.
 
Predicates
    Predicates are used to find a specific node or a node contains the specific value.
  XPath wildcards can be used to find unknown nodes.
    *                     Select any element nodes.
    @*                  Select any attribute nodes.
    node()            Match any node of any kind.

By using | operator XPath can select several paths.

XPath Axes
   An a
xes defines the node set relative to the current node.
    ancestor
    ancestor-or-self
    atribute
    child
    descendant
    descendant-or-self
    following
    following-sibling
    namespace
    parent
    preceding
    preceding-sibling
    self

Step
   A Step consists of
: an axis, a node-test, zero or more predicates.
    Each path expression consists of several steps separated by slash.
    parent::*
    child::book
    ancestor::lang
    attribute::lang