Tech Brief

Understanding XML Query Standards

The W3C grants Recommendation status to XQuery, the XML query language designed to do for Web services what SQL did for relational databases.

On Jan. 23, 2007 the W3C granted Recommendation status to XQuery, the XML query language designed to do for Web services what SQL did for relational databases. XQuery allows you to work in one common model no matter what type of data you're working with -- relational, XML or object data. It's used for queries that must represent results as XML, to query XML stored inside or outside the database, or to span relational and XML sources.

SQL/XML is another standard that uses declarative, portable queries to return XML by querying relational data. It's an extension of SQL that is part of ANSI/ISO SQL 2003. SQL/XML enables SQL queries to create XML structures with a few XML constructor functions that can be used in the SELECT statement. For a SQL programmer, SQL/XML is easy to learn because it involves additions to the existing SQL language. SQL is a mature language with many tools and infrastructure in place -- including Java Database Connectivity -- to return results.

Much as SQL has done for relational data, XQuery serves as a unifying interface for access to XML data. XML can represent any kind of data (relational, XML or object) and XQuery makes it possible to bring together both structured and unstructured data sources and process them in a unified way. As such, XQuery offers the potential to speed development, simplify data handling in Web services applications, and serve as a critical tool for service-oriented architectures (SOAs).

Why Standards for XML and Databases?
Enterprise applications access and work with data from multiple, disparate sources. Traditionally, developers haven't had a standard or easy way to integrate these data sources. For example, most Web applications have connections to databases and use XML to transfer data from the database to the Web applications and vice versa. Every major database vendor has proprietary extensions for using XML with relational databases, but most take completely different approaches and there is no interoperability.

On Web pages, XML is useful because the structure of XML closely matches the structure of HTML. But most of the data for these Web pages comes from relational databases and needs to be converted for presentation to the user. For Web messages the format is often specified by a standards organization or a trade partner, and these formats are generally hierarchical.

These examples illustrate the need for developers to have a standard way to work with all data sources -- including relational, XML, EDI and other legacy formats.

XQuery goes above and beyond SQL/XML as a query language for several reasons. Because the XQuery language is XML-centric, XQuery code is straightforward, flexible and produces any XML structure. With XQuery, there's far less code to write and maintain for the resulting XML -- providing a faster time to application deployment and lower maintenance costs. XQuery doesn't care what the data source is -- it can be any XML document, Web service, relational data and more -- while SQL/XML is limited to querying only relational data. Ultimately, XQuery provides performance and scalability at an enterprise application level that SQL/XML simply can't support.

Putting XQuery to Use
XQuery significantly simplifies data management and integration in heterogeneous environments and enables developers to build high-performance applications more quickly and efficiently. Traditionally, developers wrote a multi-step process to return data as XML by first querying the data and then writing additional transformation code using other technologies, such as XSLT. Using XQuery, the desired XML is simply returned by the query and requires no additional processing. XQuery was designed for data integration, as well as XML processing, and can easily do joins on data from different sources. For developers working in an enterprise environment comprised of multiple data sources and databases, having a single language that addresses these diverse data sources as XML lowers the costs of application development.

XQuery can query and integrate XML data from multiple data sources.
[click image for larger view]
XQuery can query and integrate XML data from multiple data sources.

Developers can utilize the power and flexibility of XQuery in many development scenarios:

  • Data integration -- for developers who need to process information from XML, relational and other data sources, XQuery can query them all, integrating information from multiple data sources in one XML query result.
  • Web services and SOA implementations -- Web services depend heavily on XML processing and data integration-tasks for which XQuery was designed. Using XQuery simplifies these tasks dramatically for the programmer and delivers significant performance improvements.
  • Report generation -- The format of the resulting XML is determined by the XQuery query. To return XML formatted differently, simply write another query. There's no need for additional transformation code to change the format. For publishing and reporting applications, XQuery makes it easy to create any view of the data -- the resulting XML can be published as HTML, PDF, PostScript and other formats.
  • Web publishing -- XQuery can be used to quickly and easily create dynamically generated HTML-based Web sites using an XML approach, which works well with AJAX applications.
But not all XQuery implementations are created equal. While the XQuery standard was defined to be data-source independent, developers are limited to the data sources supported by their XQuery engine. Fortunately, there are well-supported, reliable commercial implementations of the XQuery standard that deliver the performance and scalability necessary for large-scale XML processing needs.
comments powered by Disqus

Featured

Subscribe on YouTube