Welcome!

Linux Containers Authors: Liz McMillan, Kevin Sparenberg, Karyn Jeffery, Elizabeth White, Yeshim Deniz

Related Topics: Linux Containers, Industrial IoT, Microservices Expo

Linux Containers: Article

XQuery: A 360-Degree View

Seven-year effort produces declarative XML processing language

Extensible Markup Language, or XML, is more than a simple syntax for Internet transport. It entails a new way of thinking about information.

Different communities embrace the language for different reasons. Its platform and vendor neutrality make it a natural format for Service Oriented Architectures and Web Services. Its simple syntax is widespread and its schema flexibility makes XML attractive.

A widespread misconception says, "XML is only a syntax." While it's true that the XML 1.0 standard proposed in 1997 was simply a syntax for a file, XML has evolved beyond that humble beginning. This article studies:

  • The data model
  • The type system and processing languages underlying XML as an information model
  • The relationships between components
  • The potential impact components have on existing IT architectures
  • XQuery, the new declarative XML processing language being standardized by the W3C
An XML processing solution adds various data access APIs specifically designed for XML to existing programming languages. Such APIs are either language-specific like SAX or STAX (for Java) and XMLReader for C# or language-agnostic like DOM. They either view the XML data as a virtual or materialized conceptual tree (DOM) or as a stream of events that can be processed in a pull (STAX) or push fashion (SAX). Despite the widespread use of XML APIs in real-world applications, programming with XML at this low level of abstraction is tedious and poses a large number of performance and productivity problems.

Native XML processing languages, XPath 1.0 and XSLT 1.0, were proposed immediately after XML was standardized. XPath 1.0, made a standard in 1998, has been adopted as the basic language component that allows projection of XML content. XSLT 1.0, standardized in 1999, is a recursive template-based XML transformation language. Projection and transformation are only some of the XML processing needs. So these two languages alone can't satisfy the needs of XML processing.

XQuery, the declarative XML processing language, is a seven-year collaborative effort. It's a set of specifications, each describing a component of a global architecture. To understand XQuery, we need to understand the role of each architectural component and their interoperatation.

XML's abstract data model (XDM) forms the basis of XQuery 1.0. The 1998 XML proposal had one standardized syntax. Since one can't reason with characters, we must use an abstract data model to program this information.

XQuery is a functional language manipulating operation sequences similar to the way a programming language would operate. An XQuery program is composed of a prolog that defines the environment where the main body of the program executes. Its body is simply an expression created by recursive applications of expression constructors, starting with variables and constants. Note that XQuery programs can read existing data and compute new results based on the existing data, but can't modify existing data or modify the environment where they execute. While this is a clear usability limitation, this property ensures that traditional database query optimization techniques remain applicable.

XQuery supports several kinds of expression constructors, such as function calls, conditional expressions, and type switches. Of particular importance are two expression constructors: path expressions, FLWOR (For Let Where Orderby Return and pronounced Flower) and node constructors.

Path expressions allow navigation in a conceptual XML tree and are syntactically consistent with the design of the navigation capability of XPath 1.0. Such navigation lets XQuery explore, the children, the descendants, and the ascendants of a certain node. In addition, the name or type restrictions can be imposed on selected nodes during navigation as well as arbitrary predicates using the path filters.

The FLWOR expression constructor, based on the mathematical principles of monoids, are second-order expressions allowing iteration over a Cartesian product of sequences, filtering based on a where clause, ordering using the orderby clause, and a projection specified using a return clause. Unlike SQL, where Select From Where has a special role in the language, FLWOR expressions are just one way to build expressions in XQuery. XQuery is a fully compositional language in the sense that expressions can be nested arbitrarily in each other with no grammatical restrictions - only type restrictions are imposed.

Besides extracting existing data, XQuery can create new XML data model instances. This is done using the node constructor expressions that can be composed arbitrarily with the other kind of expressions in the language. For each kind of XML node, there's at least one way of building nodes of this kind starting with dynamically computed content. The XML elements have a syntax that's based on the native XML syntax for elements, with the additional ability to invoke dynamic expressions to compute parts of their content.

A rich built-in function library is shared among XPath 2.0, XSLT 2.0, and XQuery. It includes basic functions and frequently used operators. XQuery also allows user-defined functions in the prolog section. Each function definition includes the function name, function argument type declarations, and the expression that computes the result of the function. The body of a user-defined function is an unrestricted XQuery expression. XQuery allows extensibility through external functions that can be implemented in other programming languages and invoked from XQuery.

XQuery's type system is based on XML schema. A document describes rules for static typing of XQuery expressions and the conditions under which a program using the feature should raise type-checking errors. The typing rules are pessimistic in the sense that the type-checking phase of an expression that could raise type errors during the evaluation is required to raise a type checking error. Static typing isn't mandatory but optional in XQuery. Many implementations don't implement it or they implement a proprietary version.

XQuery is a rich XML processing language that supports expression constuctors. The ability to define functions and recursive functions make XQuery a Turing complete language. Originally intended to be a "query" language, in practice XQuery surpassed the original goal; in its current definition it's a general, declarative XML mapping language. Similar to the way SQL can be seen as a declarative way of mapping between the inputs, XQuery can be seen as a declarative mapping language between the input XML data instances and the resulting XML data model instance.

Why have two languages? In practice XSLT 2.0 and XQuery aren't competitive, but complementary ways to process XML data. Both can be applied to the same XML transformation problem, yet there are cases when XSLT is the more appropriate programming paradigm, while in other cases XQuery is. They solve the same problems using different programming paradigms: recursive templates for XSLT and iteration FLWOR for XQuery. Depending on the problem at hand or the programmers' skills, one language can be more appropriate than the other.

There are at least two major advantages to using XQuery over XSLT. XSLT's dataflow analysis is very hard to achieve given the dynamic recursive nature of the language.

An advantage XQuery offers over programming with XML APIs, like DOM or SAX, is the gain in productivity. The XQuery code that performs a certain operation is easier to write and understand than the equivalent low-level API program. XQuery has a lower level of abstraction language with XML APIs that's based on a long-term database lesson: logical/physical data independence is the golden rule in computing. If the physical representation of the data changes (the addition of a new index or a materialized view), the XQuery code simply has to be recompiled in most cases, while it has to be rewritten from scratch if the case uses a specific access pattern via an API.

XQuery's similarity in spirit with SQL is a significant advantage over XSLT, because it facilitates the learning curve of the new language and speeds up its adoption. Not to be overlooked is XQuery's greater potential for automatic optimization. The similarity in spirit with SQL makes immediately applicable almost all the optimization techniques used for optimizing relational queries. Not all such opportunities are exploited in existing XQuery engines, yet the language allows for them and it's expected that implementations will soon exploit such opportunities.

A frequent question concerns the major use-case scenarios for XQuery. In some sense the definition of XQuery as a "query language" is sometimes misleading. XQuery usability goes beyond the typical usage scenarios of the "other" query language: SQL. Unlike a SQL query that's been designed and used only as a server-side query language, XQuery has been designed as a general declarative XML processing language that can be used on persistent or temporary data and on transacted and non-transacted data. Moreover, XQuery isn't intended only for server-side execution, but it's potentially used in all the tiers of a typical architecture.

More Stories By Daniela Florescu

Dr. Daniela Florescu, along with Jonathan Robie and Don Chamberlin, developed the Quilt query language, the core language used as the basis for the developing XQuery, W3C XML Query Language.  She is also the author of numerous research papers, many with a focus on query processing, and is the co-editor of the W3C XML Query Language 1.0 specification.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Yakov Fain 06/09/06 04:12:24 PM EDT

I do not think XQuery/XPath have a bright future.
E4X is a better way to deal with XML. Hopefully more programming languages will implement this standard soon...

XML Journal News Desk 06/09/06 02:31:21 PM EDT

Extensible Markup Language, or XML, is more than a simple syntax for Internet transport. It entails a new way of thinking about information. Different communities embrace the language for different reasons. Its platform and vendor neutrality make it a natural format for Service Oriented Architectures and Web Services.

@ThingsExpo Stories
"DX encompasses the continuing technology revolution, and is addressing society's most important issues throughout the entire $78 trillion 21st-century global economy," said Roger Strukhoff, Conference Chair. "DX World Expo has organized these issues along 10 tracks with more than 150 of the world's top speakers coming to Istanbul to help change the world."
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
The financial services market is one of the most data-driven industries in the world, yet it’s bogged down by legacy CPU technologies that simply can’t keep up with the task of querying and visualizing billions of records. In his session at 20th Cloud Expo, Karthik Lalithraj, a Principal Solutions Architect at Kinetica, discussed how the advent of advanced in-database analytics on the GPU makes it possible to run sophisticated data science workloads on the same database that is housing the rich...
SYS-CON Events announced today that Massive Networks will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Massive Networks mission is simple. To help your business operate seamlessly with fast, reliable, and secure internet and network solutions. Improve your customer's experience with outstanding connections to your cloud.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution and join Akvelon expert and IoT industry leader, Sergey Grebnov, in his session at @ThingsExpo, for an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, has been named "Bronze Sponsor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, discussed the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insights from the vast t...
SYS-CON Events announced today that EnterpriseTech has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. EnterpriseTech is a professional resource for news and intelligence covering the migration of high-end technologies into the enterprise and business-IT industry, with a special focus on high-tech solutions in new product development, workload management, increased effic...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" of SYS-CON's 21st International Cloud Expo ®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...