使用XSD和XSI的XML文档上的MarkLogic TDE

时间:2017-05-18 11:42:44

标签: xml namespaces marklogic xsi

您好我正在使用MarkLogic 9.0,并且具有初学者级别的ML和XML经验。我已成功跟踪MarkLogic SQL Guide并希望在现实世界中使用它,并从事务xml文件中提取type元素。但是在我创建的视图中返回一个空结果。我认为这与xsd和xsi有关。但正如我之前提到的,我处于初级阶段,我不知道如何解决这个问题。

以下文字描述了重现问题的方案。

我将3500 xml文档加载到SQLData(具有三重存储索引)我还创建了一个SQLSchema数据库,该数据库与指南中所述的SQLData数据库相关。所有XML文档都具有类似的结构,如下例所示:

<?xml  version="1.0" encoding="UTF-8"?>
<scope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <item>
    <transaction>
      <type>CI</type>
      <sscc>00000379461100000007</sscc>
      <location>4260210630688</location>
      <device>VISTALINK.004</device>
      <date>2017-04-25</date>
      <time>01:22:20</time>
      <gmtOffset>+02:00</gmtOffset>
      <actorId>155081</actorId>
    </transaction>
    <order>
      <orderNumber>3794611</orderNumber>
    </order>
  </item>
</scope>

使用这样的URI(所有文档都有类似的结构):

/transactions/2017-04-25_01-22-20_3794611_00000379461100000007_CI.xml

现在我创建了一个具有以下结构的模板:

xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde" 
        at "/MarkLogic/tde.xqy";

let $transactions :=
<template xmlns="http://marklogic.com/xdmp/tde">
  <context>/transactions</context>
  <rows>
    <row>
      <schema-name>main</schema-name>
      <view-name>transactions</view-name>
      <columns>
        <column>
          <name>type</name>
          <scalar-type>string</scalar-type>
          <val>type</val>
        </column>
    </columns>
    </row>
  </rows>
</template>
return tde:template-insert("Transactions.xml", $transactions)

我还要将上下文更改为:

<context>item</context>

和     /项目

它不会返回任何错误,所以我认为结果会很好

当我在SQL控制台中执行以下语句时,它返回一个空结果:

select * from transactions;

当我验证上面的模板时,它会返回以下结果:

<map:map xmlns:map="http://marklogic.com/xdmp/map" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<map:entry key="valid">
<map:value xsi:type="xs:boolean">false</map:value>
</map:entry>
<map:entry key="error">
<map:value xsi:type="xs:string">TDE-INVALIDTEMPLATENODE</map:value>
</map:entry>
<map:entry key="message">
<map:value xsi:type="xs:string">TDE-INVALIDTEMPLATENODE: Invalid extraction template node: /tde:template/tde:rows/text()</map:value>
</map:entry>
</map:map>

因此验证错误是:

Invalid extraction template node: /tde:template/tde:rows/text()
Invalid extraction template node: 

/ TDE:模板/ TDE:行/文本()

有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:4)

问题出在您的背景中。您已指定<context>item</context>但根据您的示例文档itemscope的孩子。因此,您的模板应如下所示:

xquery version "1.0-ml";
import module namespace tde = "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";

let $transactions :=
<template xmlns="http://marklogic.com/xdmp/tde">
  <context>/scope/item/transaction</context>
  <rows>
    <row>
      <schema-name>main</schema-name>
      <view-name>transactions</view-name>
      <columns>
        <column>
          <name>type</name>
          <scalar-type>string</scalar-type>
          <val>type</val>
        </column>
    </columns>
    </row>
  </rows>
</template>
return tde:template-insert("Transactions.xml", $transactions)

那我们在这做什么?我们将上下文指定为/scope/item/transaction,因为您在行定义中指定的列type位于这些元素下。加载此模板将允许您运行SQL语句SELECT * FROM transactions;