Basic XQuery

Basic Hello World

xquery version "3.0" encoding "UTF-8"; let $msg := 'Hello XQuery' return <results timestamp="{current-dateTime()}"> <message>{$msg}</message> </results>

Querying a Document

xquery version "3.0"; doc("/db/apps/demo/data/hamlet.xml")/PLAY/TITLE

Querying a Collection

xquery version "3.0"; collection("/db/apps/demo/data")/PLAY/TITLE

Find all speech elements in Shakespeare with a line containing "hurlyburly"

xquery version "3.0"; collection("/db/apps/demo/data")//SPEECH[contains(LINE, "hurlyburly")]

List all speakers appearing in scene 2 of the first act of Hamlet

xquery version "3.0"; distinct-values(doc("/db/apps/demo/data/hamlet.xml")//ACT[1]/SCENE[2]//SPEAKER)