Welcome!

Linux Containers Authors: Pat Romanski, Liz McMillan, Elizabeth White, Yeshim Deniz, Roger Strukhoff

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
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices t...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
SYS-CON Events announced today that Cedexis 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. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
SYS-CON Events announced today that Google Cloud has been named “Keynote 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. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
SYS-CON Events announced today that Opsani 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. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.