【发布时间】:2012-03-20 09:37:12
【问题描述】:
我正在生成一个 XML 文档,其中为不同的部分提供了不同的 XSD(也就是说,某些元素的定义在某些文件中,其他元素的定义在其他文件中)。
XSD 文件不相互引用。架构是:
- http://xmlgw.companieshouse.gov.uk/v2-1/schema/Egov_ch-v2-0.xsd
- http://xmlgw.companieshouse.gov.uk/v1-1/schema/forms/FormSubmission-v1-1.xsd
- http://xmlgw.companieshouse.gov.uk/v1-1/schema/forms/CompanyIncorporation-v1-2.xsd
有没有办法使用 lxml 针对所有模式验证文档?
这里的解决方案不是简单地针对每个架构单独验证,因为我遇到的问题是验证失败是因为 XSD 中未指定的元素。例如,在验证 http://xmlgw.companieshouse.gov.uk/v2-1/schema/Egov_ch-v2-0.xsd 时,我收到错误:
File "lxml.etree.pyx", line 3006, in lxml.etree._Validator.assertValid (src/lxml/lxml.etree.c:125415)
DocumentInvalid: Element '{http://xmlgw.companieshouse.gov.uk}CompanyIncorporation': No matching global element declaration available, but demanded by the strict wildcard., line 9
因为有问题的文档包含{http://xmlgw.companieshouse.gov.uk}CompanyIncorporation 元素,该元素未在要验证的 XSD 中指定,而是在其他 XSD 文件之一中指定。
【问题讨论】:
-
您确定不想针对 不同 模式而不是 all验证 XML 文档的 部分 > 针对相同文档的模式?
-
我确定我想检查合并的文档是否有效。