繁体   English   中英

如何针对 MarkLogic 中的多个模式定义验证 XML 文件?

[英]How can I validate XML files against multiple schema definitions in MarkLogic?

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

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

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

I've tried moving mods-3.7.xsd and schematron.sch into the MarkLogic Schemas database and then updating the xsi:schemaLocation in the XML documents to 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"然后使用 MarkLogic 查询控制台测试验证xdmp:document-insert($new-uri, validate strict { $doc } ) 这只是返回错误: [1.0-ml] XDMP-VALIDATENODECL: (err:XQDY0084) validate strict { $doc } -- 缺少元素声明:节点 fn:doc("/Apps/theocom-maggie/scripts/ MODS-conversion/ia-to-mods.xsl")/mods:mods 在非宽松模式下使用模式 ""

帮助!

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

老实说,我认为在 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")
  )

暂无
暂无

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

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