relpipe-data/examples-xquery-atom.xml
author František Kučera <franta-hg@frantovo.cz>
Tue, 05 Feb 2019 19:18:28 +0100
branchv_0
changeset 244 d4f401b5f90c
parent 241 relpipe-data/examples.xml@f71d300205b7
child 254 23247d93a012
permissions -rw-r--r--
examples: move each example to a separate page + add generated list of examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     1
<stránka
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     2
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     3
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
0d2729ed16ed zkouška interního odkazu
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
     4
	
244
d4f401b5f90c examples: move each example to a separate page + add generated list of examples
František Kučera <franta-hg@frantovo.cz>
parents: 241
diff changeset
     5
	<nadpis>Reading an Atom feed using XQuery</nadpis>
d4f401b5f90c examples: move each example to a separate page + add generated list of examples
František Kučera <franta-hg@frantovo.cz>
parents: 241
diff changeset
     6
	<perex>converting arbitrary XML into relational data using XQuery</perex>
d4f401b5f90c examples: move each example to a separate page + add generated list of examples
František Kučera <franta-hg@frantovo.cz>
parents: 241
diff changeset
     7
	<m:pořadí-příkladu>01100</m:pořadí-příkladu>
4
1bb39595a51c genrování hlavní nabídky #1
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
     8
2
ab9099ff88fa vkládání zápatí, jmenné prostory, saxon
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
     9
	<text xmlns="http://www.w3.org/1999/xhtml">
176
46042297e0d6 relpipe-tr-validator: specification and examples
František Kučera <franta-hg@frantovo.cz>
parents: 140
diff changeset
    10
		
232
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    11
		<p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    12
			Atom Syndication Format is a standard for publishing web feeds a.k.a web syndication. 
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    13
			These feeds are usually consumed by a <em>feed reeder</em> that aggregates news from many websites and displays them in a uniform format.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    14
			The Atom feed is an XML with a list of recent news containing their titles, URLs and short annotations.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    15
			It also contains some metadata (website author, title etc.).
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    16
		</p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    17
		<p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    18
			Using this simple XQuery<m:podČarou>see <a href="https://en.wikibooks.org/wiki/XQuery">XQuery</a> at Wikibooks</m:podČarou>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    19
			<em>FLWOR Expression</em>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    20
			we convert the Atom feed into the XML serialization of relational data:
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    21
		</p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    22
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    23
		<m:pre jazyk="xq" src="examples/atom.xq" odkaz="ano"/>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    24
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    25
		<p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    26
			This is similar operation to <a href="https://www.postgresql.org/docs/current/functions-xml.html">xmltable</a> used in SQL databases.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    27
			It converts an XML tree structure to the relational form.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    28
			In our case, the output is still XML, but in a format that can be read by <code>relpipe-in-xml</code>.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    29
			All put together in a single shell script:
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    30
		</p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    31
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    32
		<m:pre jazyk="bash" src="examples/atom.sh"/>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    33
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    34
		<p>Will generate a table with web news:</p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    35
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    36
		<m:pre jazyk="text" src="examples/atom.txt"/>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    37
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    38
		<p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    39
			For frequent usage we can create a script or funcrion called <code>relpipe-in-atom</code>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    40
			that reads Atom XML on STDIN and generates relational data on STDOUT.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    41
			And then do any of these:
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    42
		</p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    43
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    44
		<m:pre jazyk="bash"><![CDATA[wget … | relpipe-in-atom | relpipe-out-tabular
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    45
wget … | relpipe-in-atom | relpipe-out-csv
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    46
wget … | relpipe-in-atom | relpipe-out-gui
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    47
wget … | relpipe-in-atom | relpipe-out-nullbyte | while read_nullbyte published title url; do echo "$title"; done
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    48
wget … | relpipe-in-atom | relpipe-out-csv | csv2rec | …
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    49
]]></m:pre>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    50
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    51
		<p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    52
			There are several implementations of XQuery.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    53
			<a href="http://galax.sourceforge.net/">Galax</a> is one of them. 
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    54
			<a href="http://xqilla.sourceforge.net/">XQilla</a> or
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    55
			<a href="http://basex.org/basex/xquery/">BaseX</a> are another ones (and support newer versions of the standard).
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    56
			There are also XSLT processors like <a href="http://xmlsoft.org/XSLT/xsltproc2.html">xsltproc</a>.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    57
			BaseX can be used instead of Galax – we just replace
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    58
			<code>galax-run -context-item /dev/stdin</code> with <code>basex -i /dev/stdin</code>.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    59
		</p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    60
		
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    61
		<p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    62
			Reading Atom feeds in a terminal might not be the best way to get news from a website,
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    63
			but this simple example learns us how to convert arbitrary XML to relational data.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    64
			And of course, we can generate multiple relations from a single XML using a single XQuery script.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    65
			XQuery can be also used for operations like JOIN or UNION and for filtering and other transformations
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    66
			as will be shown in further examples.
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    67
		</p>
c7d05cf04b76 examples: Read an Atom feed using XQuery and relpipe-in-xml
František Kučera <franta-hg@frantovo.cz>
parents: 223
diff changeset
    68
		
87
25dec6931f18 Lepší odsazení, tabulátory.
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    69
	</text>
4
1bb39595a51c genrování hlavní nabídky #1
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    70
1
a05c6f3cbc3e základ, první verze
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
</stránka>