我創建了一個.xml文件和一個模板來提取一些數據,但只有屬性出現。MarkLogic中的XQuery模板沒有顯示任何值,只有屬性(TDE)
這是我的.xml-testfile的:
<user id="1234" email="[email protected]" 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模板:節點數據的提取物(FN:DOC(TESTFILE PATH),$ userNoteTDE) 我得到以下的輸出:
{
"TESTFILE PATH": [
{
"row": {
"schema": "user",
"view": "notes",
"data": {
"rownum": "1",
"reference": "5432",
"id": "753",
"text": "",
"username": "",
"distinctiveTitle": "",
"personNameInverted": ""
}
}
}
]
}
這說明,即屬性顯示正確,但不知何故元素的值(文本,用戶名,distinctiveTitle,personNameInverted)不起作用。 我的猜測是,這些值需要更精緻的路徑或表達式,但我找不到任何信息。 如果我例如文本值更改爲我的模板<val>testns:text</val>
,我得到的錯誤:XDMP-UNBPRFX:(ERR:XPST0081)前綴testns沒有命名空間結合
於是莫名其妙的元素不能使用聲明的名稱空間,但屬性可以。
另外我跳過了我的模板中的<groups>
部分,因爲他們需要自己的上下文,那應該不重要,應該如何?
在此先感謝任何有用的見解!
既然你算出來了,請將你的答案標記爲「Accepted」,這樣很明顯這個問題得到了很好的回答。 –