Home > SOA Tips > XML Developer > Say hello to XPath 2.0
SOA Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

XML DEVELOPER

Say hello to XPath 2.0


Ed Tittel
03.28.2007
Rating: -3.83- (out of 5)


Enterprise IT tips and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Amidst the many new recommendations approved by the W3C on January 23, 2007, you'll find a brand spanking new version of XPath—namely, 2.0—to ponder. Formally entitled TR/xpath20/XML Path Language (XPath) 2.0, this document caps off what some might call the "Holy Trinity" of XML, all of which have been recently revised (or added) of late: XPath 2.0, XQuery 1.0, and XSLT 2.0. In the words of the recommendation itself "XPath 2.0 is an expression language that allows the processing of values conforming to the data model defined in [XQuery/XPath Data Model (XDM)]. The data model provides a tree representation of XML documents as well as atomic values such as integers, strings, and Booleans, and sequences that may contain both references to nodes in an XML document and atomic values. The results of an XPath expression may be a selection of nodes from the input documents, or an atomic value, or more generally, any sequence allowed by the data model."

In somewhat simpler terms this means that XQuery and XPath work together to let XML users locate and interrogate XML documents in general, and to navigate around inside a tree-structured representation of such documents for systematic end-to-end processing. XQuery handes the interrogation, and XPath the navigation. XPath expressions provide a way to address one, some, or all of the nodes in any tree representation of some XML document.

What's different between XPath 1.0 and 2.0 is that XPath 2.0 adds richer data types and gains the ability to access type information that validating documents through XML Schema can provide. In fact, strictly speaking XPath 1.0 is a subset of XPath 2.0, where 80% of the latter comes from the former. The other 20% is what's of greatest interest and includes the following kinds of materials and mechanisms:

  • XPath and XQuery are best considered as two parts of a common whole, so you must understand XPath 2.0 both in terms of the XPath 2.0 Requirements as well as the XML Query language requirements.
  • XQuery-related additions include query-wrappers that include namespace declarations, schema imports and function definitions as well as element constructors. Because XSLT 2.0 is the other XPath partner in the trinity, but doesn't need these capabilities (it's got its own), this stuff is not part of the common subset that applies to both XQuery and XSLT.
  • Schema support means that XPath 2.0 gains support for all the XML Schema primitive types (which consists of 19 simple data types, including dates and time, URIs and other complex items, as well as numbers, characters and other atomic types). Various related functions necessary to process and construct data types in XML Schema now also work in XPath 2.0, as described in "XQuery 1.0 and XPath 2.0 Functions and Operators."
  • The already cited XDM document includes complete details on what kinds of values an XPath 2.0 expression can produce. At a high level, we need only observe that such expressions can yield simple-typed values or sequences of nodes or simple-typed values (as stated in the abstract quoted earlier as well).
  • Sequences define the key focus for XPath, and a sequence is best understood in the light of a short set of rules that Evan Lenz defines in his "What's New in XPath 2.0" story for XML.com:
  • 1. Everything is a sequence: that's because in XPath 2.0 all expressions return sequences.

    2. Sequences are shallow: one sequence may not nest inside another, nesting simply produces a single sequence where the members of the nested sequence appear between the members of the top-level sequence, ad infinitum.

    3. Sequences are ordered: XPath 2.0 understands and represents clearly the order in which sequences occur, and preserves or creates whatever order you specify for results. In XPath 2.0 sequences take over for what was called node-sets in 1.0.

  • Xpath adds some important keyword operators including sequence operators such as for, conditional expressions, quantifiers, and set operations (intersection, difference, union). There's also an except operator that allows an operation to apply to all members of a sequence except for certain specific members. You'll also find lots of typecasting or coercion keywords as well.

I have to agree with Lenz's assertion that XPath 2.0, despite a relatively low percentage of change, is a major reworking of and extension to XPath 1.0. It offers lots of power and capability that XML content developers should find interesting, compelling and useful.

About the author

Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT Certification and information security topics. Among his many XML projects are XML For Dummies, 4th edition, (Wylie, 2005) and the Shaum's Easy Outline of XML (McGraw-Hill, 2004). E-mail Ed at etittel@techtarget.com with comments, questions or suggested topics or tools for review.


Rate this Tip
To rate tips, you must be a member of SearchSOA.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
XML Developer
Use the soapUI software tool to tame WSDL
WSDL 2.0, new messaging for Web services
Using RELAX NG For data integration
Efficient XML Interchange tackles data verbosity
XML to DDL imports, synchronizes database schemata
The basics of MathML 3.0
Migrating to XSLT 2.0
What's up with XML 2.0?
Podcasting software covers many bases
The XML behind podcasting

XQuery
Componentized XML Query tool takes a step forward
Try XML-based Extensible Business Reporting Language (XBRL) for accounting reports
What's new at the W3C
XQuery tutorial available
REST and Unix united
XQuery introduction
XQuery 1.0: A long time coming, now what?
Web services update for Ipedo XQuery Views
XQuery, the SQL for SOA, wins final W3C approval
Searching XML with XQuery

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



SOA Trends and Strategy - SOA Education, SOA Development, SOA Implementations
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2001 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts