Tuesday, June 12, 2012

Some facts about XPath

What is XPath, where did it come from ?
  • XPath is a language for finding information in an XML document
  • XPath uses path expressions to select nodes or node-sets in an XML document.
  • taken from here

  • XPath is part of XSLT and XQuerry. If you want to use XSLT or XQuerry you will have to learn XPath
  • In XPath, there are seven kinds of nodes: 
    • element, 
    • attribute, 
    • text, 
    • namespace, 
    • processing-instruction, 
    • comment, and 
    • document nodes.
Some terms have to be known
  • XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.
  • Atomic values are nodes with no children or parent.
  • Items are atomic values or nodes.
  • Each element and attribute has one parent.
  • Element nodes may have zero, one or more children.
  • Nodes that have the same parent are called siblings.
  • Ancestores of a node are node's parent, parent's parent, etc.
  • Descendants of a node are node's children, children's children, etc.
Selection nodes
  • XPath uses path expressions to select nodes in an XML document. 

    nodename Selects all nodes with the name "nodename"
    /
    Selects from the root node
    //
    Selects nodes in the document from the current node that match the selection no matter where they are 
    .Selects the current node
    ..
    Selects the parent of the current node
    @
    Selects attributes