0

问题

Test-Xml如果 XSD 是嵌套的(包括其他 XSD),则通过 XSD 验证 XML 将失败。

Test-Xml "C:\XML\Onix3sample_refnames.xml" -SchemaPath "C:\XML\ONIX_BookProduct_3.0_reference.xsd"

导致错误:

Test-Xml : Type 'http://ns.editeur.org/onix/3.0/reference:SourceTypeCode' is not declared, or is not a simple type.

可能的原因

ONIX_BookProduct_3.0_reference.xsd包括另外两个 XSD 文件

    <xs:include schemaLocation="ONIX_BookProduct_CodeLists.xsd"/>
    <xs:include schemaLocation="ONIX_XHTML_Subset.xsd"/>

使用嵌套 XSD 架构的 XML 验证错误中的注释- 未声明类型表明XmlReader不知道底层Stream输入的位置,因此无法加载include“d 子 XSD”。我的猜测:Test-Xml使用XmlReader.

另一个用户在 ASP.Net Core 中遇到了同样的问题

测试文件

可在https://www.editeur.org/93/Release-3.0-Downloads/下获得

XML 示例文件:https ://www.editeur.org/files/ONIX%203/ONIX_Books_3.0_sample_6.zip

XSD 架构文件:https ://www.editeur.org/files/ONIX%203/ONIX_BookProduct_XSD_schema+codes_Issue_52.zip

问题

由于我的 .NET 知识相当有限,我非常感谢 Powershell 解决方案可以根据嵌套的 XSD 模式验证 ONIX XML 文件 - 最好不必更改 XSD(由于频繁更新)。

PS:在 Notepad++/XML 工具或 XML 记事本中验证这些文件可以正常工作。

4

0 回答 0