Abstract
XQuery is a typed, functional language for querying XML, currently being designed by the XML Query Working Group of the World-Wide Web Consortium. Here are examples of XQuery queries on a suitable XML document describing books. To list titles of all books published before 2000 you might write:
document(”books.xml”)/BOOKS/BOOK[@YEAR < 2000]/TITLE
To list the year and title of all books published before 2000 you might write:
for $book in document(”books.xml”)/BOOKS/BOOK
where $book/@YEAR < 2000
return <BOOK>{ $book/@YEAR, $book/TITLE }</BOOK>
And to list for each author the titles of all books by that author you might write:
let $books := document(”books.xml”)/BOOKS
for $author in distinct($books/BOOK/AUTHOR) return
<AUTHOR NAME=”{ $author }”>{
$books/BOOK[AUTHOR = $author]/TITLE
}</AUTHOR>
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
XQuery 1.0: An XML Query Language. W3C Working Draft, April 30 (2002) (Next draft expected August 2002)
XQuery 1.0 Formal Semantics. W3C Working Draft, March 26 (2002) (Next draft expected August 2002)
XQuery 1.0 and XPath 2.0 Functions and Operators. W3C Working Draft, April 30 (2002) (Next draft expected August 2002)
Extensible Markup Language (XML) 1.0. W3C Recommendation, February 10 (1998)
Extensible Markup Language (XML) 1.0 (Second edition). W3C Recommendation, October 6 (2000)
Namespaces in XML. W3C Recommendation, January 14 (1999)
XML Schema Part 0: Primer, Part 1: Structures, Part 2: Datatypes. W3C Recommendation, May 2 (2001)
XSL Transformations (XSLT) Version 1.0. W3C Recommendation, November 16 (1999)
XSL Transformations (XSLT) Version 2.0. W3C Working Draft, April 30 (2002)
XML Path Language (XPath) 1.0. W3C Recommendation, November 16 (1999)
XML Path Language (XPath) 2.0. W3C Working Draft, April 30 (2002)
XML Pointer Language (XPointer) Version 1.0. W3C Candidate Recommendation, September 11 (2001)
RELAX NG Specification. Oasis Committee Specification, December 3 (2001)
RELAX NG Compact Syntax. Oasis Working Draft, June 7 (2002)
Fernández, M., Siméon, J., Wadler, P.: Introduction to the XQuery Formal Semantics. In: Katz, H. (ed.) XQuery for Experts. Addison-Wesley, Reading (to appear)
Siméon, J., Wadler, P.: The essence of XML. In: Proceedings 31st ACM Symposium on Principles of Programming Languages, New Orleans (January 2003)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2003 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Wadler, P. (2003). XQuery: A Typed Functional Language for Querying XML. In: Jeuring, J., Jones, S.L.P. (eds) Advanced Functional Programming. AFP 2002. Lecture Notes in Computer Science, vol 2638. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-44833-4_7
Download citation
DOI: https://doi.org/10.1007/978-3-540-44833-4_7
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-40132-2
Online ISBN: 978-3-540-44833-4
eBook Packages: Springer Book Archive