【问题标题】:How can I validate XML files against multiple schema definitions in MarkLogic?如何根据 MarkLogic 中的多个模式定义验证 XML 文件?
【发布时间】:2020-03-03 04:06:24
【问题描述】:

我在一个包含大约 130,000 个 XML 文档的 MarkLogic 数据库中工作。这些文档是使用 MODS 模式编写的,在 MODS 扩展元素中使用了一个附加的本地模式。我想做的是根据官方 MODS 3.7 xsd 和本地编写的 schematron.sch 文件验证这些文档。

如何根据 mods-3.7.xsd 和 schematron.sch 验证 MODS 命名空间中的所有元素?我们本地命名空间中的元素也需要根据 schematron.sch 进行验证。

我需要在 MarkLogic 中做什么才能以这种方式正确设置验证?

我尝试将 mods-3.7.xsd 和 schematron.sch 移动到 MarkLogic Sc​​hemas 数据库中,然后将 XML 文档中的 xsi:schemaLocation 更新为 xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-7.xsd http://www.loc.gov/mods/v3 /Schemas/schematron.sch" 然后使用 xdmp:document-insert($new-uri, validate strict { $doc } ) 在 MarkLogic 查询控制台中测试验证。这只是返回错误: [1.0-ml] XDMP-VALIDATENODECL: (err:XQDY0084) validate strict { $doc } -- 缺少元素声明:节点 fn:doc("/Apps/theocom-maggie 的预期声明/scripts/MODS-conversion/ia-to-mods.xsl")/mods:mods 在非宽松模式下使用模式“”

帮助!

【问题讨论】:

  • xsi 命名空间与 W3C XML Schema (XSD) 相关,xsi:schemaLocation 用于提示应使用哪些 XSD 对文档执行 XML Schema 验证。据我所知,文档没有一种标准化的方式来提示应该使用哪个 Schematron 模式来对文档执行 Schematron 验证。

标签: xml xsd marklogic xml-validation schematron


【解决方案1】:

请记住,schemaLocation 中架构的 uri 是在 Schemas 数据库中解析的,而不是在网络上解析的。

说实话,我认为在 MarkLogic 中最简单的方法是根本不使用 xsi:schemaLocation 属性,而是在 xqy 中显式导入模式(使用 import schema 语句),以确保它正确找到它。

顺便说一句,约书亚对 Schematron 的看法是正确的。 validate 语句不执行 Schematron 验证。但是,MarkLogic 确实提供了 schematron 支持,您可以手动应用它:

https://docs.marklogic.com/schematron

模式大致如下。您首先将 schematron 和 schema 上传到您的 schemas 数据库中。然后,您需要使用以下内容编译您的 schematron 文件:

xquery version "1.0-ml";

import module namespace schematron = "http://marklogic.com/xdmp/schematron" 
      at "/MarkLogic/schematron/schematron.xqy";

schematron:put("/schematron.sch")

之后,您使用 import schema and validate 来执行 schema 和 schematron 验证。比如:

import schema namespace mods = "http://www.loc.gov/mods/v3" at "/mods-3-6.xsd";

import module namespace schematron = "http://marklogic.com/xdmp/schematron" 
      at "/MarkLogic/schematron/schematron.xqy";

let $xml := <mods version="3.3" xmlns="http://www.loc.gov/mods/v3">

<titleInfo>
<title>FranUlmer.com -- Home Page</title>
</titleInfo>
<titleInfo type="alternative">
<title>Fran Ulmer, Democratic candidate for Governor, Alaska, 2002</title>
</titleInfo>
<name type="personal">
<namePart>Ulmer, Fran</namePart>
</name>
<genre>Website</genre>
<originInfo>
<dateCaptured point="start" encoding="iso8601">20020702 </dateCaptured>
<dateCaptured point="end" encoding="iso8601"> 20021203</dateCaptured>
</originInfo>
<language>
<languageTerm authority="iso639-2b">eng</languageTerm>
</language>
<physicalDescription>
<internetMediaType>text/html</internetMediaType>
<internetMediaType>image/jpg</internetMediaType>
</physicalDescription>
<abstract>Website promoting the candidacy of Fran Ulmer, Democratic candidate for Governor, Alaska, 2002. Includes candidate biography, issue position statements, campaign contact information, privacy policy and campaign news press releases. Site features enable visitors to sign up for campaign email list, volunteer, make campaign contributions and follow links to other internet locations. </abstract>
<subject>
<topic>Elections</topic>
<geographic>Alaska</geographic>
</subject>
<subject>
<topic>Governors</topic>
<geographic>Alaska</geographic>
<topic>Election</topic>
</subject>
<subject>
<topic>Democratic Party (AK)</topic>
</subject>
<relatedItem type="host">
<titleInfo>
<title>Election 2002 Web Archive</title>
</titleInfo>
<location>
<url>http://www.loc.gov/minerva/collect/elec2002/</url>
</location>
</relatedItem>
<location>
<url displayLabel="Active site (if available)">http://www.franulmer.com/</url>
</location>
<location>
<url displayLabel="Archived site">http://wayback-cgi1.alexa.com/e2002/*/http://www.franulmer.com/</url>
</location>
</mods>
return
  schematron:validate(
    validate strict { $xml},
    schematron:get("/schematron.sch")
  )

HTH!

【讨论】:

  • 那么除了 schematron 文件之外,我如何使用 MODS xsd 文件来验证文档?
猜你喜欢
  • 1970-01-01
  • 2010-11-08
  • 2012-07-26
  • 1970-01-01
  • 1970-01-01
  • 2012-09-01
  • 2011-07-07
  • 2013-04-14
  • 2014-10-26
相关资源
最近更新 更多