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

Recent Changes

[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] Table of Contents

[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. Searching multiple collections - How to search multiple collections in a database. Development stage: 25% (as of Dec 11th, 2008)
  4. Getting URL Parameters - How to get parameters from the URL. Development stage: 50% (as of Nov 12th, 2007)
  5. Getting POST Data - How to get XML data posted to an XQuery. Development stage: 50% (as of Nov 12th, 2007)
  6. Checking for Required Parameters - How to check for a required parameter using if/then/else. Development stage: 75% (as of Jan 21st, 2008)
  7. 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)
  8. 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)
  9. Displaying data in HTML Tables - How to display XML data in an HTML table. Development stage: 25% (as of Dec 6th, 2007)
  10. Limiting Result Sets - How to limit the number or records returned in an XQuery. Development stage: 25% (as of Sept 6th, 2006)
  11. Filtering Words - How to test to see if a word is on a list. Development stage: 50% (as of Aug 14th, 2007)
  12. 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)
  13. 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] Generic functions

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

  1. Table View - A generic table representation
  2. Tree View - A generic tree representation
  3. Searching,Paging and Sorting - Searching and Viewing

[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)
  4. Time Comparison with XQuery - Using XQuery to Compare Dated Items Development stage: 75% (as of May 4th, 2009)
  5. 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. Page scraping and Mashup
  5. Simple RSS reader
  6. Multiple page scraping and Voting behaviour
  7. Link gathering
  8. REST interface definition

[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. Employee Search - an Ajax example
  4. Incremental Search of the Chemical Elements - with Ajax
  5. XMP data
  6. Slideshow
  7. Keyword Search - full text search with google-style results

[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] 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)

[edit] Validation

  1. Validating a hierarchy


[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. IBM DB2 - XQuery using DB2 v9 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 Image:00%.svg Developing text Image:25%.svg Maturing text Image:50%.svg Developed text Image:75%.svg Comprehensive text: Image:100%.svg


indicates an XQuery/Best practice

Personal tools
Create a book