在 Python 中使用 XML 模式进行验证 [英] Validating with an XML schema in Python

查看:42
本文介绍了在 Python 中使用 XML 模式进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个文件中有一个 XML 文件和一个 XML 架构,我想验证我的 XML 文件是否符合该架构.我如何在 Python 中执行此操作?

I have an XML file and an XML schema in another file and I'd like to validate that my XML file adheres to the schema. How do I do this in Python?

我更喜欢使用标准库的东西,但如果需要,我可以安装第三方包.

I'd prefer something using the standard library, but I can install a third-party package if necessary.

推荐答案

我假设您的意思是使用 XSD 文件.令人惊讶的是,支持这一点的 Python XML 库并不多.然而,lxml 确实如此.检查 使用 lxml 进行验证.该页面还列出了如何使用 lxml 与其他模式类型进行验证.

I am assuming you mean using XSD files. Surprisingly there aren't many python XML libraries that support this. lxml does however. Check Validation with lxml. The page also lists how to use lxml to validate with other schema types.

这篇关于在 Python 中使用 XML 模式进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆