繁体   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