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.
- Sequences - Working with sequences is central to XQuery.
- Regular Expressions - Regular expressions make it easy to parse text.
- 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.
- Using XQuery Functions - How to read XQuery function documents and user XQuery functions
- Creating XQuery Functions - How to create your own local XQuery functions
- 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] Search
- Introduction to XML Search - An overview of XML search terminology
- Basic Search - A simple search page
- Searching,Paging and Sorting - Searching and Viewing search results
- Keyword Search - full text search with google-style results
- Employee Search - an Ajax example
- Incremental Search of the Chemical Elements - with Ajax
- Lucene Search - using Lucene search extensions
- Incremental Searching
[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.
- HTML Table View - A generic HTML table representation
- Tree View - A generic HTML tree representation
[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"
- Generating PDF from XSL-FO files - Converting XML-FO to PDF files
- XSL-FO Tables - Generating XSL-FO tables from XML files
[edit] XQuery Rewriting
- URL Rewriting Basics How to make your URLs look nice
[edit] XQuery Updates
- Updates and Namespaces - How updates can change serialization
[edit] Graphs
[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
- Compare with XQuery - Using XQuery to Compare Lists
[edit] Synchronization and Replication
- Time Comparison with XQuery - Using XQuery to Compare Dated Items
- Synchronizing Remote Collections - Using lastModified time stamps to see what items have changed
[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
- XHTML + Voice
[edit] Wikipedia interaction
[edit] Wikibook applications
[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.
- Overview of Page Scraping Techniques
- Page scraping and Yahoo Weather
- UK shipping forecast
- Page scraping and Mashup
- Simple RSS reader
- Multiple page scraping and Voting behaviour
- Link gathering
- REST interface definition
- Caching and indexes
[edit] Mapping
- Google Geocoding
- /String Analysis#Location_Mapping/ Mapping Car Registrations
- Flickr GoogleEarth
- Nationalgrid and Google Maps
- SMS tracker
[edit] Timelines
- Creating a Timeline - Creating a simple timeline view of events
- Timelines of Resource - Using creation and modification dates to create timelines
[edit] The Semantic Web
- DBpedia with SPARQL - Football teams
- DBpedia with SPARQL and Simile Timeline - Album Chronology Creating a timeline of album releases using data from Wikipedia
- DBpedia with SPARQL - Stadium locations
- The Emp-Dept case study
- Graphing Triples
- SPARQLing Country Calling Codes
- Southampton Pubs
- Alphabet Poster
- Simile Exhibit Browser visualizations using the Simile JavaScript libraries
- Latent Semantic Indexing Finding the semantic distance between documents
[edit] Interaction
- Adder - Creating a web service that adds two numbers.
- Simple XForms Examples
- XMP data
- Slideshow
[edit] Session Management
- Basic Session Management - the basics of session management including getting a setting session variables
[edit] Triggers
- Using Triggers to Log Events - how to set up a trigger to log store, update and remove events on a collection
[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
- XSD to XML Sample - XQuery function to generate a sample XML instance from an XML Schema file (.xsd)
[edit] Validation
- Validating a document - Validate a document with an XML Schema
- Validation using a Catalog - Using a Catalog file to validate documents
- Validating a hierarchy -
[edit] Visualization
- Graph Visualization
- Dataflow diagrams
- Sequence Diagrams
- Example Sequencer - Step-by-step tutorial
- Google Charts
- GoogleChart example - A demonstration of how to create a chart using the Google Charts API
- Histogram of File Sizes - An XQuery report that generates a histogram of file sizes
[edit] Mail Module
- Sending Email - Sending an e-mail message from XQuery
[edit] Puzzles, Maths and Games
--Dmccreary (talk) 20:58, 4 November 2009 (UTC)
[edit] eXist db specific Functions
[edit] Modules and Functions
[edit] Appendixes
[edit] Systems that Support XQuery
Using native and hybrid XML databases that implement XQuery
- DataDirect XQuery - Java XQuery engine supporting relational, EDI, flat files and XML input/output
- eXist - Open source native XML database
- DB2 pureXML - DB2 9.1 includes the pureXML feature
- MarkLogic Server - MarkLogic Server commercial XML Content Server
- Microsoft SQL Server 2005 -
- NetKernel - NetKernel
- Oracle Berkeley DB XML - Open source embedded storage management
- Oracle XML DB - Oracle Server 11g includes the XML DB (XDB) feature
- Sedna - Open source native XML Database
- Stylus Studio - XQuery mapping/editing/debugging, ships with Saxon (and SA) and DataDirect XQuery
- xDB (X-Hive/DB) - EMC Documentum xDB commercial native XML database
- XQilla - Open source XQuery library and command line utility
[edit] Live Applications
[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:
indicates an XQuery/Best practice