XQuery/Benefits
From Wikibooks, the open-content textbooks collection
[edit] Benefits of XQuery
The principal benefits of XQuery are:
- Expressiveness - XQuery can query many different data structures and its recursive nature makes it ideal for querying tree and graph structures
- Brevity - XQuery statements are shorter than similar SQL or XSLT programs
- Flexibility - XQuery can query both hierarchical and tabular data
- Consistency - XQuery has a consistent syntax and can be used with other XML standards such as XML Schema datatypes
XQuery is frequently compared with two other languages, SQL and XSLT, but has a number of advantages over these.
[edit] Advantages over SQL
Unlike SQL, XQuery returns not just tables but arbitrary tree structures. This allows XQuery to directly create XHTML structures that can be used in web pages. XQuery is for XML-based object databases, and object databases are much more flexible and powerful than databases which store in purely tabular format.
Unlike XSLT, XQuery can be learned by anyone familiar with SQL. Many of the constructs are very similar such as:
- Ordering Results: Both XQuery and SQL add an
order byclause to the query. - Selecting Distinct Values: Both XQuery and SQL have easy ways to select distinct values from a result set
- Restricting Rows: Both XQuery and SQL have a WHERE X=Y clause that can be added to an XQuery
Another big advantage is that XQuery is essentially the native query language of the World Wide Web. One can query actual web pages with XQuery, but not SQL. Even if one uses SQL-based databases to store HTML/XHTML pages or fragments of such pages, one will miss many of the advantages of XQuery's simple tag/attribute search (which is akin to searching for column names within column names).
[edit] Advantages over XSLT
Unlike XSLT, XQuery can be quickly learned by anyone familiar with SQL. XSLT has many patterns that are unfamiliar to many procedural software developers. Also, whereas XSLT is good for using as a static means to convert one type of document to another, for example RSS to HTML, XQuery is a much more dynamic querying tool, useful for pulling out sections of data from large documents and/or large number of documents.