-- Queries related to lecture on November 21, 2011 To use these examples, either install eXist (and enable its examples), or go to the XQuery sandbox (only available within ITU): http://exist.itu.dk:8080/exist/sandbox/sandbox.xql XML files used can be found at: http://itu.dk/people/pagh/idb11/exml/ -- XPath expression (also XQuery expression): doc("acm-small.xml")//node[@label="Arrays"]/../* -- Reformatting the result using XQuery: {for $topic in doc("acm-small.xml")//node[@label="Arrays"]/../*/@label/string() return {$topic}} -- For each ingredient, list of recipes containing it: declare default element namespace "http://www.brics.dk/ixwt/recipes"; { for $i in distinct-values( fn:doc("recipes.xml")//ingredient/@name ) return { for $r in fn:doc("recipes.xml")//recipe where $r//ingredient[@name=$i] return {$r/title/text()} } } -- For each ingredient used in more than one recipe, list of recipes containing it: declare default element namespace "http://www.brics.dk/ixwt/recipes"; { for $i in distinct-values( fn:doc("recipes.xml")//ingredient/@name ) let $rec := ( for $r in fn:doc("recipes.xml")//recipe where $r//ingredient[@name=$i] return {$r/title/text()} ) where count($rec)>1 return {$rec} } -- Regular expression examples using grep (unix/osx systems) grep -E "p.n..g" danske_ord.txt grep -E "^p.n..g$" danske_ord.txt grep -E "p.(n|k)..g" danske_ord.txt grep -E "la(la)+" danske_ord.txt grep -E "la(la|ma)+" danske_ord.txt grep -E "klam(m?)e" danske_ord.txt