XQuery
From Wikibooks, the open-content textbooks collection
[edit] XQuery Examples Collection
Welcome to the XQuery Examples Collection Wikibook! XQuery is a World Wide Web Consortium recommendation for selecting data from documents and databases.
[edit] Current Status
A new release of eXist (1.3Dev) is currently installed and under test. Please note any problems with these examples in the discussion
[edit] About this Project
This is a collaborative project and we encourage everyone who is using XQuery to contribute their XQuery examples. All example programs must conform to the creative-commons-2.5 share-alike with attribution license agreement [1].
Execution of examples use an eXist demo server.
- Instructors: please sign our Guest Registry if you are using this book for learning or teaching XQuery
- Contributors: please see our Naming Conventions to ensure your examples are consistent with the textbook
- Learners: If you are looking for a specific example program, please feel free to use the Examples Wanted section if you are looking for specific example programs
[edit] Table of Contents
[edit] Introduction
- Background - A brief history and motivation for the XQuery standard.
- Benefits - Why use XQuery?
- Installing and Testing - How to install an XQuery server on your .
- Naming Conventions - Naming standards used throughout this book.
[edit] Example Scripts
[edit] Beginning Examples
Examples that do not assume knowledge of functions and modules.
- HelloWorld - A simple test to see if XQuery is installed correctly.
- FLWOR Expression - A basic example of how XQuery FLWOR statements work.
- Searching multiple collections - How to search multiple collections in a database.
- Getting URL Parameters - How to get parameters from the URL.
- Getting POST Data - How to get XML data posted to an XQuery.
- Checking for Required Parameters - How to check for a required parameter using if/then/else.
- Displaying Lists - How to take a list of values in an XML structure and return a comma separated list.
- Extracting data from XHTML files - How to use the doc() function to get data from XHTML pages.
- Displaying data in HTML Tables - How to display XML data in an HTML table.
- Limiting Result Sets - How to limit the number or records returned in an XQuery.
- Filtering Words - How to test to see if a word is on a list.
- Saving and Updating Data - How to have a single XQuery that saves new records or updates existing records.
- Quantified Expressions - Testing all the items in a sequence.
[edit] Intermediate Examples
Assumes knowledge of functions and modules.
- Returning the Longest String - A function to find the longest string from a list of strings
- Net Working Days - How to calculate the number of working days between two dates
- Tag Cloud - Counting and viewing the number of keywords
- String Analysis - Regular expression string analysis
- Manipulating URIs - How to get and manage URIs
- Parsing Query Strings - Parsing query strings using alternate delimiters.
- Splitting Files - Splitting a large XML files into many smaller files.
- Filling Portlets - How to fill regions of a web page with XQuery
- Filtering Nodes - How to use the identity transform to filter out nodes
- Higher Order Functions - Passing functions as arguments to functions
- Timing Fibonacci algorithms - A couple of Fibonacci algorithms and timing display
- Using Intermediate Documents - Analysis of a MusicXML file
[edit] Generic functions
These examples use reflection on the structure of an XML document using name() to implement generic functions for XML transformations.
- Table View - A generic table representation
- Tree View - A generic tree representation
- Searching,Paging and Sorting - Searching and Viewing
[edit] Graphs and Networks
[edit] XML Differencing
- Compare two XML files - using the eXist compare() function to test to see if two XML files are exactly the same
- XML Differences - displaying the difference between two XML files
[edit] XQuery and other languages
- XQuery from SQL - Using XQuery to access a classic Relational database - Employee/Department/Salary
- XML to SQL
- XQuery and XSLT
- XQuery and Python
- Excel and XML
- XQuery and XML Schema - Generating an XML instance document
[edit] Wikipedia interaction
[edit] Wikibook applications
[edit] Page Scraping
- Page scraping and Yahoo Weather
- UK shipping forecast
- Page scraping and Mashup
- Simple RSS reader
- Multiple page scraping and Voting behaviour
- REST interface definition
[edit] Mapping
- Google Geocoding
- /String Analysis#Location_Mapping/ Mapping Car Registrations
- Flickr GoogleEarth
- Nationalgrid and Google Maps
- SMS tracker
[edit] The Semantic Web
- DBpedia with SPARQL - Football teams
- DBpedia with SPARQL and Simile Timeline - Album Chronology
- DBpedia with SPARQL - Stadium locations
- The Emp-Dept case study
- Graphing Triples
- SPARQLing Country Calling Codes
- Southampton Pubs
- Alphabet Poster
- Simile Exhibit
[edit] Interaction
- Adder - Creating a web service that adds two numbers.
- Simple XForms Examples
- Employee Search - an Ajax example
- Incremental Search of the Chemical Elements - with Ajax
- XMP data
- Slideshow
[edit] Development Tools
- Sitemap for Content Management System XQuery functions can easily perform many common web site content management functions
- Formatting Numbers - using picture formats to format numbers
- Uptime monitor
- XQuery IDE
- Image Library - using an XQuery to preview your images
[edit] Validation
[edit] Visualization
- Graph Visualization
- Dataflow diagrams
- Sequence Diagrams
- Example Sequencer - Step-by-step tutorial
- GoogleChart example
[edit] Puzzles, Maths and Games
[edit] Live Applications
[edit] Systems that Support XQuery
Using native and hybrid XML databases that implement XQuery
- eXist - eXist OpenSource native XML database
- MarkLogic Server - MarkLogic Server commercial XML Content Server
- xDB (X-Hive/DB) - EMC Documentum xDB commercial native XML database
- Sedna - Open source native XML Database
- NetKernel - NetKernel
- IBM DB2 - XQuery using DB2 v9
- Microsoft SQL Server 2005 -
- Oracle XML DB - Oracle Server 11g includes the XML DB (XDB) feature
- Oracle Berkeley DB XML - Open source embedded storage management
- XQilla - XQilla is an open source XQuery library and command line utility
- Stylus Studio - Stylus Studio has XQuery mapping/editing/debugging and ships with Saxon (and SA) and DataDirect XQuery
- DataDirect XQuery - A high performance Java XQuery engine supporting relational, EDI, flat files and XML input and output
[edit] Appendixes
[edit] Crib Sheets
[edit] Debugging XQuery
[edit] Other sources
[edit] Function Libraries
- FunctX XQuery Function Library by Priscilla Walmsley
[edit] Discussion Groups
[edit] Indexes
- Page index - generated
- Index of XQuery features - edited
- Index of Application Areas - edited
- Index of eXist modules and features - edited
Key to symbols:
| Wikibook Development Stages | ||||
|---|---|---|---|---|
| Sparse text |
Developing text |
Maturing text |
Developed text |
Comprehensive text: |
indicates an XQuery/Best practice

