user3712940
user3712940

Reputation: 39

Namespaces in XML documents in eXist-db returns empty API calls

I have an eXist-db with a collection of XML documents. All documents have a namespace in the top node which looks like this

<TEI xmlns="http://www.tei-c.org/ns/1.0" version="5.0" xml:id="No-MM_N0001-01">

When I try to query the documents for information in //div/p from the REST API I get an empty response:

Request:
/data?_query=%2F%2Fdiv%2Fp

Response:
<exist:result xmlns:exist="http://exist.sourceforge.net/NS/exist" exist:hits="0" exist:start="1" exist:count="0" exist:compilation-time="3" exist:execution-time="3"/>

But when I edit one of the documents, removing the xmlns, I get data from the document that I have edited.

Request:
/data?_query=%2F%2Fdiv%2Fp

Response:
<exist:result xmlns:exist="http://exist.sourceforge.net/NS/exist" exist:hits="2" exist:start="1" exist:count="2" exist:compilation-time="1" exist:execution-time="1">
<p>
Jeg fik ikke sove –
<del rend="overstrike">j</del>
så den
<lb/>
lille striben mellem ridauerne lysne
<lb/>
mere og mere –
<del rend="overwritten">v</del>
jeg vendte mig hed
<lb/>
i sengen – Det var
<del rend="overstrike">jo</del>
så tydeli –

So, the question is, how can I query the XML documents in my collection without editing out the namespace in all of them?

Upvotes: 1

Views: 310

Answers (1)

adamretter
adamretter

Reputation: 3517

You have many options. Just a few off the top of my head:

  1. You could send the XPath //*:div/*:p This basically uses a wildcard prefix, which means "any namespace".

  2. Instead of using HTTP GET with _query, you could HTTP Post the XQuery to the REST API, this would allow you to declare the namespace binding in your XQuery and use the appropriate XPath, e.g.

    declare namespace tei = "http://www.tei-c.org/ns/1.0";
    
    //tei:div/tei:p
    
  3. Similar to (2) but you could pre-store your XQuery in the database as a file and then call the file via a HTTP GET on the REST API, which will cause XQuery to be executed.

Other options are also possible...

Upvotes: 2

Related Questions