我创建了一个 .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) Prefix testns has no namespace binding
所以不知何故,元素不能使用声明的命名空间,但属性可以。
我也跳过了<groups>
模板中的部分,因为他们需要自己的上下文,这没关系,不是吗?
提前感谢您提供任何有用的见解!