diff -r 9c1d0c5ed599 -r d4f401b5f90c relpipe-data/examples-xquery-atom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relpipe-data/examples-xquery-atom.xml Tue Feb 05 19:18:28 2019 +0100 @@ -0,0 +1,71 @@ + + + Reading an Atom feed using XQuery + converting arbitrary XML into relational data using XQuery + 01100 + + + +

+ Atom Syndication Format is a standard for publishing web feeds a.k.a web syndication. + These feeds are usually consumed by a feed reeder that aggregates news from many websites and displays them in a uniform format. + The Atom feed is an XML with a list of recent news containing their titles, URLs and short annotations. + It also contains some metadata (website author, title etc.). +

+

+ Using this simple XQuerysee XQuery at Wikibooks + FLWOR Expression + we convert the Atom feed into the XML serialization of relational data: +

+ + + +

+ This is similar operation to xmltable used in SQL databases. + It converts an XML tree structure to the relational form. + In our case, the output is still XML, but in a format that can be read by relpipe-in-xml. + All put together in a single shell script: +

+ + + +

Will generate a table with web news:

+ + + +

+ For frequent usage we can create a script or funcrion called relpipe-in-atom + that reads Atom XML on STDIN and generates relational data on STDOUT. + And then do any of these: +

+ + + +

+ There are several implementations of XQuery. + Galax is one of them. + XQilla or + BaseX are another ones (and support newer versions of the standard). + There are also XSLT processors like xsltproc. + BaseX can be used instead of Galax – we just replace + galax-run -context-item /dev/stdin with basex -i /dev/stdin. +

+ +

+ Reading Atom feeds in a terminal might not be the best way to get news from a website, + but this simple example learns us how to convert arbitrary XML to relational data. + And of course, we can generate multiple relations from a single XML using a single XQuery script. + XQuery can be also used for operations like JOIN or UNION and for filtering and other transformations + as will be shown in further examples. +

+ +
+ +