< XQuery

Motivation

You have data stored in a Google Docs spreadsheet. Since Google docs has an RSS feed for their data you can use this service to get well-formed XML about your spreadsheet directly from XQuery.

Method

You can use the base URL of 'https://spreadsheets.google.com/feeds/list/' to list the data in a public spreadsheet.

let $base-uri := 'https://spreadsheets.google.com/feeds/list/'
let $document-id := '0AsuPP847sJrUdEdwcVdHeUZ1Sm80dEc1eWZHQkwyZlE'
let $suffix := '/od6/public/basic'

you can concat these three strings together and wrap them in an xs:anyURI type to get the document using the httpcleint:get() function.

Example Code

xquery version "1.0";
declare namespace atom="http://www.w3.org/2005/Atom";

let $http-get :=
   httpclient:get(
     xs:anyURI(
        'https://spreadsheets.google.com/feeds/list/0AsuPP847sJrUdEdwcVdHeUZ1Sm80dEc1eWZHQkwyZlE/od6/public/basic'),
     true(), ())
 
 return
 <results>
    Number Entries: { count($http-get//atom:entry) }
 </results>

Which returns:

   <results>Number Entries: 455</results>

References

This example was posted on the eXist mailing list in April of 2014 by Dr. Andreas Wagner.

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.