繁体   English   中英

具有XSD和XSI的XML文档上的MarkLogic TDE

[英]MarkLogic TDE on XML documents with XSD and XSI

您好,我正在使用MarkLogic 9.0,并且对ML和XML具有初学者的经验。 我已经成功地遵循了《 MarkLogic SQL指南》,并希望在现实世界中使用它,并从事务性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:template / tde:rows / text()

有谁知道我该如何解决?

问题出在您的情况下。 您已经指定了<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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM