SQL Foundations  «Prev  Next»
Lesson 11

Querying XML Database

In the coming modules, you will learn the specifics about
  1. inserting,
  2. querying, and
  3. working
with the information in your databases and tables. Right now, take a deep breath and realize that this is just the beginning. Think about how SQL can be used to manipulate data stored in relational databases.

An XML database is a data persistence software system that allows data to be imported, accessed and exported in the XML format.

Two major classes of XML database exist:

  1. XML-enabled: These map all XML to a traditional database (such as a relational database), accepting XML as input and rendering XML as output.
  2. Native XML (NXD) The internal model of such databases depends on XML and uses XML documents as the fundamental unit of storage.
Note: "XML-enabled" implies that the database does the conversion itself (as opposed to relying on middleware).


XQuery, Linked Data, and the Semantic Web

If you are working with RDF, whether as RSS feeds or as Semantic Web Linked Data, XQuery has something to offer you.
You can fairly easily generate RSS and RDF/XML with XQuery, of course. The query language for RDF is called SPARQL, and there is even a SPARQL query processor written in XQuery that turns out to be faster than many native SPARQL engines. SPARQL engines can produce results in XML, and that too can be processed with XQuery. XML and RDF both have their separate uses, as do SPARQL and XQuery, and you can use them together when it makes sense.

XQuery

  1. XQuery is a W3C-standardized language for querying documents and data.
  2. XQuery operates on instances of the XPath and XQuery Data Model, so you can use XQuery to work with anything that can build a suitable model. This often includes relational databases and RDF triple stores
  3. Objects in the data model and objects and values created by XQuery expressions have types as defi ned by W3C XML Schema.
  4. XQuery and XSLT both build on XPath; XSLT is an XML-syntax language which includes XPath expressions inside attributes and XQuery uses XPath syntax extended with more keywords.
  5. There are XQuery processors (sometimes called XQuery engines) that work inside relational databases, accessing the underlying store directly rather than going through SQL.
  6. There are also XML-native databases, and some XQuery engines just read fi les from the hard drive, from memory, or over the network.
  7. XQuery Update is a separate specifi cation for making changes to data model instances.
  8. XPath and XQuery Full Text is a separate specifi cation for full-text searching of XML documents or other data model instances.
  9. XQuery Scripting is a separate specifi cation that adds procedural programming to XQuery, but it is currently not a fi nal specifi cation.
  10. The two most important building-blocks of XQuery are the FLWOR expression and functions.
  11. XQuery FLWOR stands for for-let-where-order by-return.
  12. User-defi ned functions can be recursive, and can be collected together along with userdefined read-only variables into separate library fi les called modules.