[英]XQuery template in MarkLogic doesn't show any values, only attributes (TDE)
我创建了一个.xml文件和一个模板以提取一些数据,但是仅显示属性。
这是我的.xml测试文件:
<user id="1234" email="test.user@live.com" password="1234">
<type>Human</type>
<notes>
<note reference="5432" id="753" xmlns="http://testnamespace.de/note">
<text>example</text>
<username>John Doe</username>
<groups>
<group id="42">Avengers</group>
<group id="55">JLA</group>
</groups>
<distinctiveTitle>title</distinctiveTitle>
<personNameInverted>Doe John</personNameInverted>
</note>
</notes>
这里是相应的模板:
import module namespace tde = "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";
declare namespace testns = "http://testnamespace.de/note";
let $userNoteTDE:=
<template xmlns="http://marklogic.com/xdmp/tde" xmlns:testns="http://testnamespace.de/note">
<context>/user/notes/testns:note</context>
<rows>
<row>
<schema-name>user</schema-name>
<view-name>notes</view-name>
<columns>
<column>
<name>reference</name>
<scalar-type>string</scalar-type>
<val>@reference</val>
<nullable>true</nullable>
<default>""</default>
</column>
<column>
<name>id</name>
<scalar-type>string</scalar-type>
<val>@id</val>
<nullable>true</nullable>
<default>""</default>
</column>
<column>
<name>text</name>
<scalar-type>string</scalar-type>
<val>text</val>
<nullable>true</nullable>
<default>""</default>
</column>
<column>
<name>username</name>
<scalar-type>string</scalar-type>
<val>username</val>
<nullable>true</nullable>
<default>""</default>
</column>
<column>
<name>distinctiveTitle</name>
<scalar-type>string</scalar-type>
<val>distinctiveTitle</val>
<nullable>true</nullable>
<default>""</default>
</column>
<column>
<name>personNameInverted</name>
<scalar-type>string</scalar-type>
<val>personNameInverted</val>
<nullable>true</nullable>
<default>""</default>
</column>
</columns>
</row>
</rows>
</template>
我更改了上下文,以使用正确的(?)路径和名称空间(因为这部分应嵌套在另一个模板中):
<context>/user/notes/testns:note</context>
如果使用tde:node-data-extract(fn:doc( TESTFILE PATH ),$ userNoteTDE)检查模板,则会得到以下输出:
{
"TESTFILE PATH": [
{
"row": {
"schema": "user",
"view": "notes",
"data": {
"rownum": "1",
"reference": "5432",
"id": "753",
"text": "",
"username": "",
"distinctiveTitle": "",
"personNameInverted": ""
}
}
}
]
}
这表明属性正确显示,但是以某种方式,元素的值(文本,用户名,与众不同的标题,personNameInverted)不起作用。 我的猜测是,这些值需要更精细的路径或表达式,但是我找不到任何信息。 如果我在模板中将文本值例如更改为<val>testns:text</val>
, 则会收到错误: XDMP-UNBPRFX:(err:XPST0081)前缀testns没有命名空间绑定
因此,元素某种程度上不能使用声明的名称空间,但是属性可以使用。
我也跳过了模板中的<groups>
部分,因为它们将需要自己的上下文,这应该没关系吗?
在此先感谢您提供任何有用的见解!
MarkLogic支持人员给了我这个问题的答案,所以我想在这里分享!
(感谢克里斯·哈姆林!)
这确实是一个名称空间问题。 MarkLogic文档显示,对于多个名称空间,应使用“路径名称空间”。
申报后
...
<path-namespaces>
<path-namespace>
<prefix>testns</prefix>
<namespace-uri>http://testnamespace.de/note</namespace-uri>
</path-namespace>
</path-namespaces>
...
在模板和上下文之间,并在我的元素(如testns:text)上使用testns前缀,这些元素将正确显示!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.