Welcome!

Linux Containers Authors: Elizabeth White, Yeshim Deniz, Liz McMillan, Pat Romanski, Stackify Blog

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
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
Most people haven’t heard the word, “gamification,” even though they probably, and perhaps unwittingly, participate in it every day. Gamification is “the process of adding games or game-like elements to something (as a task) so as to encourage participation.” Further, gamification is about bringing game mechanics – rules, constructs, processes, and methods – into the real world in an effort to engage people. In his session at @ThingsExpo, Robert Endo, owner and engagement manager of Intrepid D...
Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
Michael Maximilien, better known as max or Dr. Max, is a computer scientist with IBM. At IBM Research Triangle Park, he was a principal engineer for the worldwide industry point-of-sale standard: JavaPOS. At IBM Research, some highlights include pioneering research on semantic Web services, mashups, and cloud computing, and platform-as-a-service. He joined the IBM Cloud Labs in 2014 and works closely with Pivotal Inc., to help make the Cloud Found the best PaaS.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution. In his session at @ThingsExpo, Akvelon expert and IoT industry leader Sergey Grebnov provided 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.
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abilit...
In his session at Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to maximize project result...
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 to ...
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, discussed the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Two weeks ago (November 3-5), I attended the Cloud Expo Silicon Valley as a speaker, where I presented on the security and privacy due diligence requirements for cloud solutions. Cloud security is a topical issue for every CIO, CISO, and technology buyer. Decision-makers are always looking for insights on how to mitigate the security risks of implementing and using cloud solutions. Based on the presentation topics covered at the conference, as well as the general discussions heard between sessio...
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and ...