diff -r ea49ee7a73c9 -r c7d05cf04b76 relpipe-data/examples.xml --- a/relpipe-data/examples.xml Fri Jan 11 22:39:05 2019 +0100 +++ b/relpipe-data/examples.xml Fri Jan 11 22:39:30 2019 +0100 @@ -687,6 +687,67 @@

+

Read an Atom feed using XQuery and relpipe-in-xml

+ +

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

+ +