Python - 使用 lxml 验证多个模式

发布于 2024-09-08 03:28:22 字数 371 浏览 1 评论 0原文

我正在使用由第三方构建的架构,我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

芸娘子的小脾气 2024-09-15 03:28:22

如果 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文