When paths and queries collide

Ed Tittel discusses the convergence of two XML technologies--namely XPath and XQuery--in their forthcoming standard editions.


XML Developer Tip

When paths and queries collide
Ed Tittel

In a stellar article on www.xml.com entitled "What's New in XPath 2.0," author Evan Lenz (http://www.xml.com/pub/a/2002/03/20/xpath2.html) lays out the new capabilities of the next-generation of XPath in a clear and concise fashion. What's absolutely fascinating about this story is that it reveals the convergence of two XML technologies--namely XPath and XQuery--in their forthcoming standard editions.

Those already in the know about XSLT, XPointer, and other related XML technologies also know that XPath provides a notation whereby individual objects in an XML document can be specified, located, and "messed with." In many ways, XQuery supports similar, if more general-purpose, functionality in that it defines a syntax whereby individual objects in an XML document can be accessed, their contents inspected, and so forth. As you might expect, in its original design XPath was considered more of a navigational or locational tool, whereas XQuery was always equally focused on identifying and qualifying objects by class, type, and hierarchical position, as well as by its location within the context of the document itself.

What fascinates me about Lenz's story in general, and the continuing convergence of XPath and XQuery capabilities, is the designers' realization that looking for objects is the underlying activity that gives both XPath and XQuery their reasons for existence, and that therefore the two standards should have as much in common as possible. In fact, Lenz points out that about 80% of what's in XQuery also rightfully pertains to XPath. A nice side effect of this convergence will be that learning XPath 2.0 will get cognoscenti more than halfway toward the goal of learning XQuery as well. Especially for those who seek to interrogate, search, classify, or selectively parse the contents of XML documents, this is a very good thing.

The brief answer to the question that entitles Lenz's story ("What's new in XML 2.0") is as follows (read his story for a lengthier discussion of this and related topics):

  • XPath 2.0 supports a large collection of datatypes; specifically, it supports all 19 primitive data types defined for XML Schema. This makes it much easier to operate on dates, URIs, and other more complex data objects than in XPath 1.0.
  • XPath 2.0 offers a richer, more succinct syntax for building expressions by which to qualify (and select) XML document contents. It's nice when things get more powerful and easier to use at the same time!
  • XPath 2.0 is a strict subset of XQuery 1.0; according to Lenz, "both working drafts and language grammars were automatically generated from a common source..." What differentiates the two (the missing 20%, in other words) is high-level constructs that XSLT already supplies (and that XQuery alone needs, since XPath is most likely to be used along with XSLT or some other higher-level markup language).
  • Richer support for nodes (document objects) in XPath 2.0 include association of elements and attributes with XML Schema types, and associated handling capabilities. This is a great convenience for those who must process XML document content based on XML Schema definitions.

There's a lot more where this came from, but the upshot is that by converging common functionality between XPath 2.0 and XQuery 1.0 and sticking to common syntax and capabilities, XPath's capabilities have taken a great leap forward in the transition from 1.0 to 2.0. Check out Lenz's article for more details including pointers to the important draft and final specification documents at the W3C. It's a nice sign that XML is delivering on its promises to make things easier, more consistent, with powerful syntax when these kinds of things actually occur.

Have questions, comments, or feedback about this or other XML-related topics? Please e-mail me care of tips@searchwebservices.com; I'm always glad to hear from my readers.



About the Author

Ed Tittel is a principal at LANWrights, Inc., a wholly owned subsidiary of LeapIt.com. LANWrights offers training, writing, and consulting services on Internet, networking, and Web topics (including XML and XHTML), plus various IT certifications (Microsoft, Sun/Java, and Prosoft/CIW).

For More Information

  • Need help with the latest industry acronyms and terms? Visit our helpful Glossary.
  • Visit our Best Web Links for the best editor-selected XML resources on the Web.
  • Post your technical questions, or help your peers in our Enterprise Developer Forums.
  • Ask the Experts! Our Web Services, SOAP, WSDL, XML, .NET, Java and EAI gurus answer your toughest questions.


This was first published in April 2002

Dig deeper on XML and XML schema

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close