XML
  Home arrow XML arrow Page 4 - Navigating Input Documents Using Paths
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
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

Navigating Input Documents Using Paths
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-21

    Table of Contents:
  • Navigating Input Documents Using Paths
  • Steps and changing context
  • Node Tests
  • Abbreviated Syntax

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Navigating Input Documents Using Paths - Abbreviated Syntax


    (Page 4 of 4 )

    Some axes and steps can be abbreviated, as shown in Table 4-3. The abbreviations "." and ".." are used as the entire step (with no node test).  "." represents the current context node itself, regardless of its node kind. Likewise, the step ".." represents the parent node, which could be either an element node or a document node.

    Table 4-3. Abbreviations

    Abbreviation

    Meaning

    .

    self::node()

    ..

    parent::node()

    @

    attribute::

    //

    /descendant-or-self::node()/

    The @ abbreviation, on the other hand, replaces the axis only, so it is used along with a node test or wildcard. For example, you can use @dept to select dept attributes, or @* to select all attributes.

    The // abbreviation is a shorthand to indicate a descendant anywhere in a tree. For example, catalog//number will match all number elements at any level among the descendants of catalog. You can start a path with .// if you want to limit the selection to descendants of the current context node.

    Table 4-4 shows additional examples of abbreviated and unabbreviated syntax.

    Table 4-4. Abbreviated and unabbreviated syntax examples

    Unabbreviated syntaxAbbreviated equivalent
    child::productproduct
    child::**
    self::node().
    attribute::dept@dept
    attribute::*@*
    descendant::product.//product
    child::product/descendant::nameproduct//name
    parent::node/number../number

    Other Expressions As Steps

    In addition to axis steps, other expressions can also be used as steps. You have already seen this in use in:

      doc("catalog.xml")/catalog/product/number

    where doc("catalog.xml") is a function call that is used as a step. You can include more complex expressions, for example:

      doc("catalog.xml")/catalog/product/(number | name)

    which uses the parenthesized expression (number | name) to select all number and name elements. The | operator is a union operator; it selects the union of two sets of nodes.

    If the expression in a step contains an operator with lower precedence than /, it needs to be in parentheses. Some other examples of more complex steps are provided in Table4-5.

    Table 4-5. More complex steps (examples start with doc("catalog.xml")/catalog/)

    Example

    Meaning

    product/(number | name)

    All numberAND namechildren of product.

    product/(* except number)

    All children of productexcept number. See "Combining Results" in Chapter 9 for more information on the |and exceptoperators.

    product/ (if (desc) then desc else name)

    For each productelement, the descchild if it exists; otherwise, the namechild.

    product/substring(name,1,30)

    A sequence of xs:stringvalues that are substrings of product names.

    The last step (and only the last step) in a path may return atomic values rather than nodes. The last example in Table 4-5 will return a sequence of atomic values that are the substrings of the product names. An error is raised if a step that is not the last returns atomic values. For example:

      product/substring(name,1,30)/replace(.,' ','-')

    will raise an error because the substring step returns atomic values, and it is not the last step.

    Please check back next week for the continuation of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "XQuery," published by O'Reilly. We hope...
     

    XML ARTICLES

    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands
    - Creating an XUL App Installer
    - Overlays in XUL
    - Skinning Your Custom XUL Applications







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