relpipe-data/examples-xquery-atom.xml
author František Kučera <franta-hg@frantovo.cz>
Mon, 21 Feb 2022 01:21:22 +0100
branchv_0
changeset 330 70e7eb578cfa
parent 262 846510a73535
permissions -rw-r--r--
Added tag relpipe-v0.18 for changeset 5bc2bb8b7946
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
		
254
23247d93a012 examples: atom → recfile
František Kučera <franta-hg@frantovo.cz>
parents: 244
diff changeset
    38
		<p>Or with <code>relpipe-out-recfile</code>, we will get output in the recfile format (<a href="https://www.gnu.org/software/recutils/">GNU Recutils</a>), like this:</p>
23247d93a012 examples: atom → recfile
František Kučera <franta-hg@frantovo.cz>
parents: 244
diff changeset
    39
		
23247d93a012 examples: atom → recfile
František Kučera <franta-hg@frantovo.cz>
parents: 244
diff changeset
    40
		<m:pre jazyk="text" src="examples/atom.rec"/>
23247d93a012 examples: atom → recfile
František Kučera <franta-hg@frantovo.cz>
parents: 244
diff changeset
    41
		
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
    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
			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
    44
			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
    45
			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
    46
		</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
    47
		
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
		<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
    49
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
    50
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
    51
wget … | relpipe-in-atom | relpipe-out-nullbyte | while read_nullbyte published title url; do echo "$title"; done
254
23247d93a012 examples: atom → recfile
František Kučera <franta-hg@frantovo.cz>
parents: 244
diff changeset
    52
wget … | relpipe-in-atom | relpipe-out-recfile
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
    53
]]></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
    54
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
		<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
    56
			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
    57
			<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
    58
			<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
    59
			<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
    60
			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
    61
			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
    62
			<code>galax-run -context-item /dev/stdin</code> with <code>basex -i /dev/stdin</code>.
262
846510a73535 examples: atom – XQilla
František Kučera <franta-hg@frantovo.cz>
parents: 254
diff changeset
    63
			Or for XQilla we use: <code>xqilla -i /dev/stdin</code>.
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
    64
		</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
    65
		
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
		<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
    67
			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
    68
			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
    69
			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
    70
			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
    71
			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
    72
		</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
    73
		
87
25dec6931f18 Lepší odsazení, tabulátory.
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    74
	</text>
4
1bb39595a51c genrování hlavní nabídky #1
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    75
1
a05c6f3cbc3e základ, první verze
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
</stránka>