Python - 使用 lxml 验证多个模式
我正在使用由第三方构建的架构,我想使用 lxml 对其进行验证。问题是这样的模式被分割在不同的 xsd 文件中,这些文件引用了它们自己。
例如,一个名为“extension.xsd”的文件(基于“master”模式构建)有这样一行:
<redefine schemaLocation="master.xsd">
如果我尝试使用 lxml 验证它(解析,然后使用 XMLSchema
然后验证另一个我知道已经有效的文档),我只使用“扩展”而不是“主”进行验证:换句话说,验证失败(因为在 XML 文件中,某些元素仅存在于“主”中,而不是“扩展”中”)。
我该如何解决(或解决)这个问题?谢谢!
I'm working with a schema that was built by a third party and I'd like to validate it with lxml. The problem is that such a schema is split over different xsd files, which reference themselves.
For example, a file called "extension.xsd" (which builds upon the "master" schema) has a line like:
<redefine schemaLocation="master.xsd">
If I try to validate it with lxml (parsing, then using XMLSchema
then validating another document which I know is valid already), I only get validation using "extension" and not "master": in other words, the validation fails (because in the XML file there are elements only present in "master" and not in "extension").
How can I solve (or work around) this issue? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 lxml 不支持“重新定义”,最好的选择是修复它并提交补丁。 :)
如果失败,解决方法是自己解析 master.xsd 文件,然后应用扩展名.xsd 中的更改,并输出具有组合架构的单个 xsd 文件。
If lxml doesn't support "redefine", the best option would be to fix it and submit a patch. :)
Failing that, the workaround would be to parse the master.xsd file yourself, and then apply the changes from extension.xsd, and output a single xsd file with the combined schema.