Search code examples
xqueryexist-dboxygenxml

Running XQuery in oXygen: Can't access Nodes Within a Document Node


I want to write a query that returns a specific element within an XML document, but when I use a path expression to return an element within a document (i.e. beyond the Document Node), it always returns an empty sequence.

Here's the first few lines of the XML I want to query:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
    schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
   <teiHeader>
      <fileDesc>
         <titleStmt>
            <title>LMW Day Book, pp. 160-161</title>

I can run queries on the Document Nodes. For example, the following returns the Document Nodes in reverse alphabetical order:

for $file in collection("/db/apps/Step3_LMWdbk_Jana's_Files")
order by $file descending
return $file

I can also use the doc() function to return a single Document Node. However, I can't use path expressions to return nodes within the Document Node. For example, the following returns an empty sequence:

let $title := doc("/db/apps/Step3_LMWdbk_Jana's_Files")/TEI/teiHeader/fileDesc/titleStmt/title
return $title

What I've ruled out:

To test further, I wrote several more queries, including one to access the outermost element (i.e. doc(...)/TEI), and one to access all of the elements (i.e. doc(...)//cell): they all returned an empty sequence. This suggests mistakes in the path expressions aren't the fundamental problem.

I'm running XQuery in oXygen XML Editor. I've connected an eXist database to oXygen and I'm using the XQuery engine offered by the eXist database. I've checked that I'm connected to the eXist, and that my transformation scenario is using eXist as it's transformer.


Solution

  • Note that the document has a default namespace <TEI xmlns="http://www.tei-c.org/ns/1.0"> so prefix your query with declare default element namespace "http://www.tei-c.org/ns/1.0". As you don't show the entire document there may be other namespaces used.