0

一部のデータを抽出するために .xml ファイルとテンプレートを作成しましたが、属性しか表示されません。

これは私の .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-extract(fn:doc ( TESTFILE PATH ), $userNoteTDE) でチェック すると、次の出力が得られます。

    {
"TESTFILE PATH": [
  {
    "row": {
     "schema": "user", 
     "view": "notes", 
     "data": {
      "rownum": "1", 
      "reference": "5432", 
      "id": "753", 
      "text": "", 
      "username": "", 
      "distinctiveTitle": "", 
      "personNameInverted": ""
     }
    }
   }
  ]
 }

これは、属性が正しく表示されていることを示していますが、要素の値 (text、username、distinctTitle、personNameInverted) が機能していません。私の推測では、値にはより洗練されたパスまたは式が必要ですが、情報が見つかりません。たとえば、テンプレートでテキスト値を変更すると、次のエラーが表示されます: XDMP-UNBPRFX: (err:XPST0081) Prefix testns has no namespace binding<val>testns:text</val>

したがって、どういうわけか、要素は宣言された名前空間を使用できませんが、属性は使用できます。

また、テンプレートのセクションをスキップしました<groups>。これは、独自のコンテキストが必要になるためです。それは問題ではないはずです。

有益な洞察を事前にありがとう!

4

1 に答える 1