简体   繁体   English

eXist-db中XML文档中的命名空间返回空的API调用

[英]Namespaces in XML documents in eXist-db returns empty API calls

I have an eXist-db with a collection of XML documents. 我有一个带有XML文档集合的eXist-db。 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: 当我尝试从REST API查询// div / p中的信息时,我得到一个空响应:

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. 但是,当我编辑其中一个文档时,删除xmlns,我从已编辑的文档中获取数据。

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? 因此,问题是,如何在不删除所有文档中名称空间的情况下查询集合中的XML文档?

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". 您可以发送XPath //*:div/*:p这基本上使用通配符前缀,表示“任何名称空间”。

  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, eg 代替将HTTP GET与_query ,您可以将XQuery HTTP张贴到REST API,这将允许您在XQuery中声明名称空间绑定并使用适当的XPath,例如

     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. 与(2)相似,但是您可以将XQuery作为文件预先存储在数据库中,然后通过REST API上的HTTP GET调用该文件,这将导致XQuery被执行。

Other options are also possible... 其他选项也是可能的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM