Reputation: 41
I've created a .xml-file and a template to extract some data, but only the attributes show up.
This is my .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>
and here the corresponding template:
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>
I changed the context to use the correct (?) path and the namespace (because this part should be nested into another template):
<context>/user/notes/testns:note</context>
If I check the template with tde:node-data-extract(fn:doc (TESTFILE PATH), $userNoteTDE) I get the following output:
{
"TESTFILE PATH": [
{
"row": {
"schema": "user",
"view": "notes",
"data": {
"rownum": "1",
"reference": "5432",
"id": "753",
"text": "",
"username": "",
"distinctiveTitle": "",
"personNameInverted": ""
}
}
}
]
}
This shows, that the attributes are displayed correctly, but somehow the values (text, username, distinctiveTitle, personNameInverted) of the elements do not work.
My guess is, that the values need a more refined path or expression, but I can't find any information.
If I change the text value for example to <val>testns:text</val>
in my template, I get the error: XDMP-UNBPRFX: (err:XPST0081) Prefix testns has no namespace binding
So somehow the elements can't use the declared namespace, but the attributes can.
Also I skipped the <groups>
section in my template, because they would need a context on their own, that shouldn't matter, should it?
Thanks in advance for any helpful insight!
Upvotes: 0
Views: 183
Reputation: 41
The MarkLogic Support gave me the answer for this problem, so I want to share it here!
(Thanks Chris Hamlin!)
It was indeed a namespace problem. The MarkLogic Documentation shows that for multiple namespaces "path-namespaces" should be used.
After declaring
...
<path-namespaces>
<path-namespace>
<prefix>testns</prefix>
<namespace-uri>http://testnamespace.de/note</namespace-uri>
</path-namespace>
</path-namespaces>
...
between template and context, and using the testns prefix on my elements like testns:text, the elements are being correctly displayed!
Upvotes: 4