我如何针对MarkLogic中的多个架构定义来验证XML文件?

问题描述 投票:1回答:1

我正在MarkLogic数据库中工作,该数据库大约有130,000个XML文档。这些文档是使用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 /脚本/MODS-conversion/ia-to-mods.xsl")/mods:mods使用模式“”处于非宽松模式。

帮助!

xml xsd marklogic xml-validation schematron
1个回答
1
投票

请记住,SchemaLocation中的模式uri是在Schemas数据库中而不是在网络上解决的。

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

Joshua对Schematron的看法是正确的。 validate语句不执行Schematron验证。 MarkLogic确实提供了schematron支持,您可以改为手动应用:

https://docs.marklogic.com/schematron

该模式大致如下。首先,将schematron和架构上载到架构数据库中。然后,您需要使用类似的方法来编译您的schematron文件:

xquery version "1.0-ml";

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

schematron:put("/schematron.sch")

之后,您将使用导入架构并进行验证以进行架构和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!

© www.soinside.com 2019 - 2024. All rights reserved.