Lab: XML Database - Basics - Store and Query XML (optional)
Thursday 12th November 2026
Thursday 12th November 2026
Storing and Querying an XML Document in Elemental
Writing FLWOR Expressions
Joining data togeter
First we will store a single document into Elemental using eXide
Find the file hindawi-example.xml in the provided Exercises folder at: Exercises/samples/hindawi-example.xml
From the File Menu in eXide, enter the DB Manager:
hindawi-example.xml file from your Computer
Refresh the Directory side-panel in eXide
/db/hindawi-example.xml document to open it from the databaseUsing eXide, write an XQuery for the Journal Article
Query /db/hindawi-example.xml
Produce an XML report of the authors names, similar to:
<authors>
<author>Priscilla Walmsley</author>
<author>Adam Retter</author>
<author>Michael Kay</author>
<author>Tomos Hillman</author>
</authors>
Hint: XQuery components you could use include:
For BindingWhere Clausefn:concat function
<authors>
{
for $contrib in //contrib-group/contrib
where $contrib/@contrib-type eq "author"
return
<author>{concat($contrib/name/given-names, " ", $contrib/name/surname)}</author>
}
</authors>
Produces the report:
<authors>
<author>Bo Zhang</author>
<author>Wenxu Xie</author>
<author>Yong Xiang</author>
</authors>
<authors>
{
for $contrib in //contrib-group/contrib
where $contrib/@contrib-type eq "author"
return
<author>{concat($contrib/name/given-names, " ", $contrib/name/surname)}</author>
}
</authors>
For Binding: for each contrib child element present in the //contrib-group element(s), bind each in turn to the variable $contrib
Where Clause: but only where each contrib element (referenced by $contrib) has a contrib-type attribute with the value equal to author
Return Clause: for each thing we have bound, evaluate the next expression
Concat Function: concatenates one or more strings together into a single string
<authors>
{
for $name in doc("/db/hindawi-example.xml")
//contrib-group/contrib[@contrib-type eq "author"]/name
return
<author>{$name/given-names || " " || $name/surname}</author>
}
</authors>
Doc Function: retrieves a document using the URI /db/hindawi-example.xml specified, and typically returns its document-node()
Predicate: Only where the context item ( contrib element) has a contrib-type attribute with the value equal to author
String Concatenation Expression: syntactic sugar for fn:concat(a, b)
Using eXide, write an XQuery for the Journal Article
Query /db/hindawi-example.xml
Produce an XML report of the references to articles ordered by year (most recent first) and title:
<references>
<article year="1999" doi="12.1234/ab123456a">Why Cat Memes dominate the Internet, and its impact on the psychology of dog owners</article>
<article year="1995" doi="12.1234/ab123456b">How Dragonfruit developed its Colour</article>
</references>
Hint: XQuery components you could use include:
Let BindingOrder By Clausexs:integer type constructor
<references>
{
for $cite in doc("/db/hindawi-example.xml")
//ref[@content-type eq "article"]/nlm-citation
let $year :=
if ($cite/year)
then xs:integer($cite/year)
else 0
order by $year descending, $cite/article-title ascending
return
<article year="{$year}" doi="{$cite/pub-id[@pub-id-type eq 'doi']}">
{
$cite/article-title/text()
}
</article>
}
</references>
Using eXide, write an XQuery:
Query /db/hindawi-example.xml
From the articles' authors, produce an XML report of the references which were also likely authored by the same people. Similar to:
<article year="2014" title="Key Observations of Retterpotomus Social Interactions">
<authors>
<author surname="Retter" given-names="Adam"/>
</authors>
<self-refs>
<article year="2011" title="Upon the Discovery of The Retterpotomus">
<author surname="Retter" given-names="A."/>
</article>
</self-refs>
</article>
let $article := doc("/db/hindawi-example.xml")/article
let $authors := $article//contrib-group/contrib[@contrib-type eq "author"]/name
return
<article year="{$article//pub-date[@pub-type eq 'publication-year']/year}" title="{$article//article-meta//article-title}">
{ $authors ! <author surname="{surname}" given-names="{given-names}"/> }
<self-refs>
{
for $cite in $article
//ref[ @content-type eq "article"]/nlm-citation[.//surname = $authors/surname]
return
<article year="{$cite/year}" title="{$cite/article-title/text()}">
{
$cite/person-group[ @person-group-type eq "author"]/name !
<author surname="{surname}" given-names="{given-names}"/>
}
</article>
}
</self-refs>
</article>
How to store a document into Elemental
How to query a document in Elemental
FLWOR Expressions
Joining data together