簡體   English   中英

如何根據 Marklogic 查詢控制台中 Schemas 數據庫中的模式驗證特定數據庫中的 XML 文檔?

[英]How can I validate XML documents in a specific database against a schema in the Schemas database in Marklogic's query console?

使用 Marklogic 10 的查詢控制台。 我正在嘗試針對已加載到 Schemas 數據庫中的兩種不同模式驗證 XML 文檔。 我要驗證的 XML 文檔位於我創建的名為“myDatabase”的數據庫中。 我希望能夠對數據庫中的現有文檔運行驗證,並在將新文檔插入數據庫之前運行驗證。

我編寫了兩個不同的查詢(驗證現有文檔,另一個在文檔創建之前運行),但讓它們在 Query Console 中工作的唯一方法是,如果我選擇 Documents 數據庫,選擇 App-Services 服務器,然后使用xdmp:eval()從“myDatabase”獲取文檔。

我的問題是,如何在不使用xdmp:eval()解決方法的情況下對“myDatabase”中的文檔運行這些查詢?

我包括以下查詢:

xquery version "1.0-ml";

(: Validate existing documents :)

import schema namespace mods = "http://www.loc.gov/mods/v3" at "/mods-3-7.xsd";
import module namespace schematron = "http://marklogic.com/xdmp/schematron" at "/MarkLogic/schematron/schematron.xqy";   
declare namespace svrl = "http://purl.oclc.org/dsdl/svrl";  

let $query := 
  "xquery version '1.0-ml';
  let $doc := fn:doc('/test.xml')
  return $doc"
let $docs := xdmp:eval($query, (),
                <options xmlns="xdmp:eval">
                  <database>{xdmp:database("myDatabase")}</database>
                </options>)
for $doc in $docs
return 
(
  try { concat(fn:document-uri(validate strict {$doc}), "&#xa;  MODS validation passed") }
  catch ($e) { concat("MODS validation failed: ", $e/error:format-string/text()) },

  schematron:validate($doc, schematron:get("/schematron.sch"))/svrl:schematron-output/svrl:failed-assert/svrl:text/concat("  Schematron error - ", text())
)
xquery version "1.0-ml";

(: Validate new documents before loading :)

import module namespace schematron = "http://marklogic.com/xdmp/schematron" at "/MarkLogic/schematron/schematron.xqy";   
declare namespace svrl = "http://purl.oclc.org/dsdl/svrl";  

let $node := xdmp:document-get("temp/test.xml")
let $query := 
  "xquery version '1.0-ml';
  import schema namespace mods = &quot;http://www.loc.gov/mods/v3&quot; at &quot;/mods-3-7.xsd&quot;;
  import module namespace schematron = &quot;http://marklogic.com/xdmp/schematron&quot; at &quot;/MarkLogic/schematron/schematron.xqy&quot;; 
  declare variable $node as node()* external;
  xdmp:document-insert('/test.xml', validate strict {$node} )"
return
  (
    try { 
          xdmp:eval($query, (xs:QName('node'), $node),
            <options xmlns="xdmp:eval">
              <database>{xdmp:database("myDatabase")}</database>
            </options>)
        }
    catch ($e) { "Validation failed: ",
                 $e/error:format-string/text() },

    schematron:validate($node, schematron:get("/schematron.sch"))/svrl:schematron-output/svrl:failed-assert/svrl:text/concat("  Schematron error - ", text())
  )  

更新:如果我嘗試運行驗證查詢,甚至只是嘗試在文檔以外的任何數據庫中編譯 schematron,我會收到以下錯誤消息:

[1.0-ml] XDMP-NODB: xdmp:eval("declare variable $validator-uri as xs:string external;&#10;decla...", (fn:QName("","validator-uri"), "/schematron.sch-validator.xsl", fn:QName("","validator-xslt"), ...), <options xmlns="xdmp:eval"><database>0</database></options>) -- No database with identifier 0

簡短回答,檢查是否選擇Schemas作為myDatabase文檔數據庫的架構數據庫。

您評估的應用服務器決定了應該使用哪些文檔和模塊數據庫。 文檔數據庫反過來指示哪些模式和觸發器數據庫與之相配。 如果您在 Admin UI 中創建一個空數據庫,默認情況下它會將架構和觸發器設置為(none) 同樣可能適用於創建數據庫的其他方法。

哼!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM