Lab: XML Database - Basics - Store and Query XML (optional)

Thursday 12th November 2026

Learning Objectives

Storing your first XML Document into Elemental

Storing your first XML Document into Elemental

  1. Click the Upload cloud icon
  2. Click the "Upload Files" button
  3. Choose the hindawi-example.xml file from your Computer
  4. Click the "x Done" button

Storing your first XML Document into Elemental

  1. Refresh the Directory side-panel in eXide

  2. Click the /db/hindawi-example.xml document to open it from the database
  3. Open the document, and spend a couple of minutes examining the XML

First FLWOR

Hint: XQuery components you could use include:

  • For Binding
  • Predicate or Where Clause
  • fn:concat function

First FLWOR – Solution 1


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

First FLWOR – Solution 1 details


      <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>
    
  1. For Binding: for each contrib child element present in the //contrib-group element(s), bind each in turn to the variable $contrib

  2. Where Clause: but only where each contrib element (referenced by $contrib) has a contrib-type attribute with the value equal to author

  3. Return Clause: for each thing we have bound, evaluate the next expression

  4. Concat Function: concatenates one or more strings together into a single string

First FLWOR – Improved, Solution 2


      <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>
    
  1. Doc Function: retrieves a document using the URI /db/hindawi-example.xml specified, and typically returns its document-node()

  2. Predicate: Only where the context item ( contrib element) has a contrib-type attribute with the value equal to author

  3. String Concatenation Expression: syntactic sugar for fn:concat(a, b)

Full FLWOR

Using eXide, write an XQuery for the Journal Article

Hint: XQuery components you could use include:

  • Let Binding
  • Order By Clause
  • Text Node Kind Test
  • xs:integer type constructor

Full FLWOR - Solution


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

FLWOR Join

Using eXide, write an XQuery:

FLWOR Join - Solution


      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>
    

First Session: What have we learned?