[英]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>
但是根據您的示例文檔item
是scope
的子級。 因此,您的模板應如下所示:
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.