簡體   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