Database Reference
In-Depth Information
Listing with the xmldb Extension Module
Another way to return a list is by using one of eXist's extension modules, xmldb (see
“Controlling the Database from Code” on page 107 ). An extension module contains
functions that perform actions that are difficult or impossible to do in standard
XQuery. eXist has quite a lot of them, and Appendix A lists the most important ones.
If you want to explore the wonderful features that extension modules have to offer,
you can access their documentation through the dashboard's XQuery Function Doc‐
umentation tile.
Instead of the code entered in the previous section, try the following:
xmldb:get-child-resources ( "/db/apps/exist101/data" )
Your result window should now show a list of the play's resource names (but without
their paths). So, where the collection function returned a document-node sequence,
xmldb:get-child-resources returns a string sequence. To get from a string to inside
the XML (to get the name of the play), we have to resolve a document-node from this
string. For this we use the XPath doc function (see “The doc Function” on page 94 ).
So, without further ado, Example 3-3 shows a piece of code that returns exactly the
same results as the code in Example 3-2 , but by a different means.
Example 3-3. Getting the play information using an extension function
xquery version "3.0" ;
<plays>
{
let $ data-collection := "/db/apps/exist101/data"
for $ resource-name in xmldb:get-child-resources ( $ data-collection )
let $ uri := concat ( $ data-collection , '/' , $ resource-name )
return
<play uri = "{ $ uri }"
name = "{ util:unescape-uri ( $ resource-name , "UTF-8" )}" >
{
doc ( $ uri )/ PLAY / TITLE / text ()
}
</play>
}
</plays>
Listing the Plays (HTML)
As a next step, let's present this information to the user as a nicely formatted HTML
page. For this we have to (you might have guessed) create the HTML ourselves,
including pieces like headers. For now we won't bother to make it look fancy by using
CSS and the like, but of course you can add that too if you want.
Search WWH ::




Custom Search