Databases Reference
In-Depth Information
This XPath expression may be unfamiliar to many, but its structure isn't complex.
You tell the system to start at the current figure, count the number of preceding fig-
ures in the chapter, and add one to get the current figure number. To make finding
path expressions easy, there are also XML tools that allow you to select any element in
an XML file, and the tools will show you the path expression required to select that
specific element.
XPath is a key component that makes managing complexity easy. If you were using
SQL, you'd need to store your complex data in many tables and use joins to extract
the right data. Although an individual RDBMS table may have a simple structure, stor-
ing complex data in SQL usually requires complex queries. Native XML systems are
just the opposite. Even if the data is complex, there are often simple XPath expres-
sions that can be used to efficiently get the data you need out of the system.
Unlike other XML systems, native XML databases tend to use short, single-element
XPath expressions because each individual element is indexed as it's added to the
database. For example, the path expression collection('/my-collection')//
PersonBirthDate will find all the person birth date records in a collection even if
each document has a radically different structure. The downside to this is that you
need more disk space to store your XML data. The upside is that queries are simple
and fast.
Now that you have a feel for how XPath works, let's look at how the XQuery lan-
guage is used to integrate XPath expressions to deliver a full solution that converts
XML data directly into other structures.
5.2.4
Transforming your data with XQuery
Using the XQuery language and its advanced functional programming and parallel
query execution features allows you to rapidly and effortlessly transform large data-
sets. In the NoSQL world, XQuery replaces both SQL and application-level functional
programming languages with a single language.
One of the greatest advantages of using native XML databases over other docu-
ment stores is how they use the XQuery language to transform XML data. As you'll
see, XQuery is designed to query tabular as well as unstructured document data.
XQuery is a mature and widely adopted standardized query language, carefully con-
structed by query experts using a rigorous peer review process. Although other lan-
guages can be used with native XML databases, XQuery is preferred due to its
advanced functional structure and ability to run on parallel systems. A sample of
XQuery is shown in figure 5.6.
As we move into our next few sections, you'll see why users that need to query large
amounts of unstructured data prefer XQuery over other transformation languages.
XQ UERY A FLEXIBLE LANGUAGE
The XQuery language was developed by the World Wide Web consortium ( W3C ), the
same organization that defined many other web and XML standards. Not long after
XML standards were published, the W3C formed a standards body that included many
Search WWH ::




Custom Search