XQuery

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

Contents

[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.4) is currently installed and under test. Please note any problems with these examples in the discussion

Recent Changes

[edit] New and Revised Articles

[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.

  1. Instructors: please sign our Guest Registry if you are using this book for learning or teaching XQuery
  2. Contributors: please see our Naming Conventions to ensure your examples are consistent with the textbook
  3. 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] Introduction

  1. Background - A brief history and motivation for the XQuery standard. Development stage: 00% (as of Sept 27th, 2006)
  2. Benefits - Why use XQuery? Development stage: 00% (as of Sept 27th, 2006)
  3. Installing and Testing - How to install an XQuery server on your . Development stage: 00% (as of Sept 27th, 2006)
  4. Naming Conventions - Naming standards used throughout this book. Development stage: 00% (as of March 17th, 2006)

[edit] Example Scripts

[edit] Beginning Examples

Examples that do not assume knowledge of functions and modules.

  1. HelloWorld - A simple test to see if XQuery is installed correctly. Development stage: 75% (as of Jan 21st, 2008)
  2. FLWOR Expression - A basic example of how XQuery FLWOR statements work. Development stage: 75% (as of Jan 21st, 2008)
  3. Sequences - Working with sequences is central to XQuery. Development stage: 25% (as of Sept. 26st, 2009)
  4. Regular Expressions - Regular expressions make it easy to parse text. Development stage: 25% (as of Sept. 26st, 2009)
  5. Searching multiple collections - How to search multiple collections in a database. Development stage: 25% (as of Dec 11th, 2008)
  6. Getting URL Parameters - How to get parameters from the URL. Development stage: 50% (as of Nov 12th, 2007)
  7. Getting POST Data - How to get XML data posted to an XQuery. Development stage: 50% (as of Nov 12th, 2007)
  8. Checking for Required Parameters - How to check for a required parameter using if/then/else. Development stage: 75% (as of Jan 21st, 2008)
  9. Displaying Lists - How to take a list of values in an XML structure and return a comma separated list. Development stage: 50% (as of Nov 6th, 2007)
  10. Extracting data from XHTML files - How to use the doc() function to get data from XHTML pages. Development stage: 25% (as of Aug 6th, 2008)
  11. Displaying data in HTML Tables - How to display XML data in an HTML table. Development stage: 25% (as of Dec 6th, 2007)
  12. Limiting Result Sets - How to limit the number or records returned in an XQuery. Development stage: 25% (as of Sept 6th, 2006)
  13. Filtering Words - How to test to see if a word is on a list. Development stage: 50% (as of Aug 14th, 2007)
  14. Saving and Updating Data - How to have a single XQuery that saves new records or updates existing records. Development stage: 50% (as of Oct 24th, 2007)
  15. Quantified Expressions - Testing all the items in a sequence. Development stage: 25% (as of Oct 29th, 2008)

[edit] Intermediate Examples

Assumes knowledge of functions and modules.

  1. Using XQuery Functions - How to read XQuery function documents and user XQuery functions
  2. Creating XQuery Functions - How to create your own local XQuery functions
  3. Returning the Longest String - A function to find the longest string from a list of strings
  4. Net Working Days - How to calculate the number of working days between two dates Development stage: 25% (as of Aug 14th, 2007)
  5. Tag Cloud - Counting and viewing the number of keywords Development stage: 75% (as of Aug 17th, 2007)
  6. String Analysis - Regular expression string analysis
  7. Manipulating URIs - How to get and manage URIs
  8. Parsing Query Strings - Parsing query strings using alternate delimiters. Development stage: 25% (as of Aug 24th, 2007)
  9. Splitting Files - Splitting a large XML files into many smaller files. Development stage: 25% (as of Aug 24th, 2007)
  10. Filling Portlets - How to fill regions of a web page with XQuery
  11. Filtering Nodes - How to use the identity transform to filter out nodes Development stage: 25% (as of Feb 13th, 2008)
  12. Higher Order Functions - Passing functions as arguments to functions Development stage: 25% (as of Nov 10th, 2008)
  13. Timing Fibonacci algorithms - A couple of Fibonacci algorithms and timing display
  14. Using Intermediate Documents - Analysis of a MusicXML file

[edit] Search

  1. Introduction to XML Search - An overview of XML search terminology Development stage: 25% (as of July 30th, 2009)
  2. Basic Search - A simple search page Development stage: 25% (as of Oct 1st, 2009)
  3. Searching,Paging and Sorting - Searching and Viewing search results Development stage: 25% (as of July 30th, 2009)
  4. Keyword Search - full text search with Google-style results Development stage: 75% (as of July 30th, 2009)
  5. Employee Search - an Ajax example Development stage: 25% (as of July 30th, 2009)
  6. Incremental Search of the Chemical Elements - with Ajax Development stage: 25% (as of July 30th, 2009)
  7. Lucene Search - using eXist's Lucene-based fulltext search Development stage: 25% (as of July 30th, 2009)
  8. Incremental Searching

[edit] Browsing

  1. Navigating Collections - an example of an AJAX browser Development stage: 25% (as of Nov 29th, 2009)

[edit] Reporting

[edit] Creating Custom Views

These examples use reflection on the structure of an XML document using name() to implement generic functions for XML transformations.

  1. HTML Table View - A generic HTML table representation
  2. Tree View - A generic HTML tree representation
  3. Grouping Items - how to group items in a report

[edit] Paginated Reports

Unlike HTML pages, paginated reports use the concept of text flows between pages. These examples show you how to convert raw XML into high-quality PDF files suitable for printing. The examples use a markup standard called XSLFO for "Formatted Objects"

  1. Generating PDF from XSL-FO files - Converting XML-FO to PDF files Development stage: 25% (as of September 22nd, 2009)
  2. XSL-FO Tables - Generating XSL-FO tables from XML files Development stage: 25% (as of September 22nd, 2009)

[edit] Notification

When an event gets trigged there are several ways to notify users. Sending an e-mail message or creating an entry in an atom feed are to examples of notification services.

  1. Sending E-mail - How to send an e-mail message from within an XQuery Development stage: 25% (as of November 19th, 2009)

[edit] URL Rewriting

  1. URL Rewriting Basics How to make your URLs look nice Development stage: 25% (as of November 4th, 2009)

[edit] XQuery Updates

  1. Updates and Namespaces - How updates can change serialization Development stage: 25% (as of October 25th, 2009)

[edit] Graphs

  1. Topological Sort

[edit] XML Differencing

  1. Compare two XML files - using the eXist compare() function to test to see if two XML files are exactly the same Development stage: 75% (as of Oct 17th, 2008)
  2. XML Differences - displaying the difference between two XML files Development stage: 25% (as of Nov 6th, 2008)
  3. Compare with XQuery - Using XQuery to Compare Lists Development stage: 75% (as of May 4th, 2009)

[edit] Synchronization and Replication

  1. Time Comparison with XQuery - Using XQuery to Compare Dated Items Development stage: 75% (as of May 4th, 2009)
  2. Synchronizing Remote Collections - Using lastModified time stamps to see what items have changed Development stage: 25% (as of May 4th, 2009)

[edit] XQuery and other languages

  1. XQuery from SQL - Using XQuery to access a classic Relational database - Employee/Department/Salary
  2. XML to SQL
  3. XQuery and XSLT
  4. XQuery and Python Development stage: 25% (as of Jul 23rd, 2008)
  5. Excel and XML
  6. XQuery and XML Schema - Generating an XML instance document
  7. XHTML + Voice

[edit] Wikipedia interaction

  1. Wikipedia Page scraping
  2. Wikipedia Lookup
  3. Wikipedia Events RSS
  4. Wiki weapons page

[edit] Wikibook applications

  1. Wikibook index page
  2. Wikibook list of code links

[edit] Page Scraping

Page scraping is the process of extracting well-formed XML data from any HTML web page. When creating mashup applications this is also known as the harvesting process.

  1. Overview of Page Scraping Techniques Development stage: 25% (as of March 30th, 2009)
  2. Page scraping and Yahoo Weather
  3. UK shipping forecast
  4. BBC Weather Forecast
  5. Page scraping and Mashup
  6. Simple RSS reader
  7. Multiple page scraping and Voting behaviour
  8. Link gathering
  9. REST interface definition
  10. Caching and indexes

[edit] Mapping

  1. Google Geocoding
  2. /String Analysis#Location_Mapping/ Mapping Car Registrations
  3. Flickr GoogleEarth
  4. Nationalgrid and Google Maps
  5. SMS tracker

[edit] Timelines

  1. Creating a Timeline - Creating a simple timeline view of events Development stage: 50% (as of March 1st, 2009)
  2. Timelines of Resource - Using creation and modification dates to create timelines Development stage: 25% (as of March 2nd, 2009)

[edit] The Semantic Web

  1. DBpedia with SPARQL - Football teams
  2. DBpedia with SPARQL and Simile Timeline - Album Chronology Creating a timeline of album releases using data from Wikipedia Development stage: 75% (as of Feb 5th, 2009)
  3. DBpedia with SPARQL - Stadium locations
  4. The Emp-Dept case study
    1. XML to RDF
    2. SPARQL Tutorial
    3. SPARQL interface
  5. Graphing Triples
  6. SPARQLing Country Calling Codes
  7. Southampton Pubs
  8. Alphabet Poster
  9. Simile Exhibit Browser visualizations using the Simile JavaScript libraries Development stage: 25% (as of Feb 5th, 2009)
  10. Latent Semantic Indexing Finding the semantic distance between documents Development stage: 25% (as of Feb 5th, 2009)

[edit] Interaction

  1. Adder - Creating a web service that adds two numbers. Development stage: 25% (as of Sept 6th, 2007)
  2. Simple XForms Examples
  3. XMP data
  4. Slideshow
  5. Pachube feed

[edit] Session Management

  1. Basic Session Management - the basics of session management including getting a setting session variables Development stage: 25% (as of Sept 6th, 2007)

[edit] Triggers

  1. Using Triggers to Log Events - how to set up a trigger to log store, update and remove events on a collection Development stage: 25% (as of July 10th, 2009)

[edit] Development Tools

  1. Sitemap for Content Management System XQuery functions can easily perform many common web site content management functions Development stage: 25% (as of Aug 27st, 2008)
  2. Formatting Numbers - using picture formats to format numbers Development stage: 100% (as of Nov 18th, 2008)
  3. Uptime monitor
  4. XQuery IDE
  5. Image Library - using an XQuery to preview your images Development stage: 25% (as of Nov 18th, 2008)
  6. XSD to XML Sample - XQuery function to generate a sample XML instance from an XML Schema file (.xsd)
  7. Lorum Ipsum text

[edit] Validation

  1. Validating a document - Validate a document with an XML Schema Development stage: 75% (as of July 29th, 2009)
  2. Validation using a Catalog - Using a Catalog file to validate documents Development stage: 25% (as of July 29th, 2009)
  3. Validating a hierarchy - Development stage: 25% (as of July 29th, 2009)

[edit] Visualization

  1. Graph Visualization
  2. Dataflow diagrams
  3. Sequence Diagrams
  4. Example Sequencer - Step-by-step tutorial
  5. Google Charts
  6. GoogleChart example - A demonstration of how to create a chart using the Google Charts API
  7. Histogram of File Sizes - An XQuery report that generates a histogram of file sizes

[edit] Puzzles, Maths and Games

  1. Fizzbuzz
  2. Project Euler
  3. Sudoku

[edit] eXist db specific Functions

[edit] Modules and Functions

  1. List Modules
  2. Modules and Functions
  3. Dynamic Module Loading


[edit] Appendixes

[edit] Systems that Support XQuery

Using native and hybrid XML databases that implement XQuery Development stage: 00% (as of Feb 15th, 2007)

  1. DataDirect XQuery - Java XQuery engine supporting relational, EDI, flat files and XML input/output
  2. eXist - Open source native XML database Development stage: 00% (as of Feb 15th, 2007)
  3. DB2 pureXML - DB2 9.1 includes the pureXML feature Development stage: 00% (as of Mar 19th, 2007)
  4. MarkLogic Server - MarkLogic Server commercial XML Content Server Development stage: 00% (as of Feb 15th, 2007)
  5. Microsoft SQL Server 2005 - Development stage: 00% (as of Mar 19th, 2007)
  6. NetKernel - NetKernel Development stage: 00% (as of Feb 15th, 2007)
  7. Oracle Berkeley DB XML - Open source embedded storage management Development stage: 00% (as of Nov 5th, 2008)
  8. Oracle XML DB - Oracle Server 11g includes the XML DB (XDB) feature Development stage: 00% (as of Nov 5th, 2008)
  9. Sedna - Open source native XML Database Development stage: 00% (as of Jov 1st, 2007)
  10. Stylus Studio - XQuery mapping/editing/debugging, ships with Saxon (and SA) and DataDirect XQuery
  11. xDB (X-Hive/DB) - EMC Documentum xDB commercial native XML database Development stage: 00% (as of Dec 17th, 2008)
  12. XQilla - Open source XQuery library and command line utility Development stage: 00% (as of Nov 5th, 2008)

[edit] Live Applications

  1. UWE StudentsOnline

[edit] Crib Sheets

[edit] Debugging XQuery

  1. Gotchas - some pitfalls
  2. Ahhas - some ahha moments


[edit] Other sources

[edit] Function Libraries

  1. FunctX XQuery Function Library by Priscilla Walmsley

[edit] Discussion Groups

  1. XQuery General


[edit] Indexes

Key to symbols:

Wikibook Development Stages
Sparse text 00%.svg Developing text 25%.svg Maturing text 50%.svg Developed text 75%.svg Comprehensive text: 100%.svg


XForms-best-practice.jpg indicates an XQuery/Best practice