XML
  Home arrow XML arrow Page 4 - XPath Basics
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XPath Basics
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2001-08-15

    Table of Contents:
  • XPath Basics
  • Dog Days
  • First Steps
  • Revolving Around An Axis
  • Proof Of The Pudding
  • Playing Chicken
  • Operating With Extreme Caution
  • Be Cool
  • The Next Step

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    PCmover - $15 Off with Coupon Code CJPH7Q

    XPath Basics - Revolving Around An Axis
    (Page 4 of 9 )

    Since the first component of a location step is the axis, let's deal with that first. An axis defines the relationship between the current node and the nodes to be selected - whether, for example, they are children of the current node, siblings of the current node, or the parent of the current node.

    The XPath specification defines the following axes:

    self - the "self" axis refers to the context node itself;

    parent - the "parent" axis selects the parent of the context node;

    child - the "child" axis selects the children of the context node;

    attribute - the "attribute" axis refers to the attributes of the context node;

    These are the most commonly-used ones; however, it's quite likely that you'll also find a use for:

    ancestor - the "ancestor" axis selects the parent, grandparent, great-grandparent and all other ancestors of the context node;

    descendant - the opposite of the "ancestor" axis, this axis selects the children (and children's children) of the context node;

    ancestor-or-self - this variant of the "ancestor" axis selects all ancestors of the context node as well as the node itself;

    descendant-or-self - this variant of the "descendant" axis selects all descendants of the context node as well as the node itself;

    following-sibling and preceding-sibling - these two axes contain the nodes at the same level in the document tree as the context node. Depending on which axis you use, you will get a collection of siblings which are either after or before the context node, in document order.

    following and preceding - the "following" axis selects all nodes within the document tree which follow (are placed after) the context node, while the "preceding" axis selects all nodes which come before the context node.

    namespace - the "namespace" axis selects all the nodes in the same namespace as the context node;

    Once the relationship to be established has been defined and an appropriate node collection obtained, a node test can be used to further filter the items in the collection. This node test is connected to the axis by a double colon (::) symbol.

    Typically, you would select a node on the basis of its name without using a node test; in such a case, the node type is deduced from the axis part of the location step. If, on the other hand, you'd like to select nodes on the basis of type, XPath offers some pre-defined node tests; the text() node test selects text nodes, the comment() function selects comments, the processing-instruction() function selects PIs and the generic node() function selects any and all nodes.

    Finally, in case the resulting collection needs to be further broken down, XPath allows you to add optional predicates to each location step, enclosed within square braces.

    This article copyright Melonfire 2001. All rights reserved.

    More XML Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    XML ARTICLES

    - How to Set Up Podcasting and Vodcasting
    - Creating an RSS Reader Application
    - Building an RSS File
    - An Introduction to XUL Part 6
    - An Introduction to XUL Part 5
    - An Introduction to XUL Part 4
    - An Introduction to XUL Part 3
    - An Introduction to XUL Part 2
    - An Introduction to XUL Part 1
    - XML Matters: Practical XML Data Design and M...
    - Practical XML Data Design and Manipulation f...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway