我已经创建了一个.xml-file和一个模板来提取一些数据,但仅显示属性。
这是我的.xml-testfile:
<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-tracktract(fn:doc( testfile path ),$ usernotetde)我得到以下输出:
{
"TESTFILE PATH": [
{
"row": {
"schema": "user",
"view": "notes",
"data": {
"rownum": "1",
"reference": "5432",
"id": "753",
"text": "",
"username": "",
"distinctiveTitle": "",
"personNameInverted": ""
}
}
}
]
}
这表明属性显示正确显示,但是某种程度上,这些元素的值(文本,用户名,独特的,personnamevered)不起作用。我的猜测是,这些值需要更精致的路径或表达方式,但是我找不到任何信息。如果我更改 text 例如在模板中的 <val>testns:text</val>
中,我会得到错误: xdmp-unbprfx :( err:err:xpst0081)prefix testns prefix testns没有名称空间bink
所以某种程度上元素不能使用声明的名称空间,但是属性可以。
我也跳过了模板中的<groups>
部分,因为它们会自己需要上下文,这没关系,应该吗?
事先感谢您的任何有用的见解!
标记支持给了我这个问题的答案,所以我想在这里分享!
(感谢Chris Hamlin!)
这确实是一个命名空间问题。标记文档显示,应使用多个名称空间"路径名"。
声明
...
<path-namespaces>
<path-namespace>
<prefix>testns</prefix>
<namespace-uri>http://testnamespace.de/note</namespace-uri>
</path-namespace>
</path-namespaces>
...
模板和上下文,以及在我的元素上使用 testns 前缀,例如 testns:text ,元素正在正确显示!