在没有非python依赖项的情况下在Python中验证XML

时间:2022-05-15 00:45:40

I'm writing a small Python app for distribution. I need to include simple XML validation (it's a debugging tool), but I want to avoid any dependencies on compiled C libraries such as lxml or pyxml as those will make the resulting app much harder to distribute. I can't find anything that seems to fit the bill - for DTDs, Relax NG or XML Schema. Any suggestions?

我正在编写一个小型Python应用程序进行分发。我需要包含简单的XML验证(它是一个调试工具),但我想避免对已编译的C库(如lxml或pyxml)的任何依赖,因为这些将使得生成的应用程序更难分发。我找不到任何符合条件的东西 - 对于DTD,Relax NG或XML Schema。有什么建议?

4 个解决方案

#1


4  

Do you mean something like MiniXsv? I have never used it, but from the website, we can read that

你的意思是MiniXsv吗?我从未使用过它,但是从网站上我们可以读到它

minixsv is a lightweight XML schema validator package written in pure Python (at least Python 2.4 is required).

minixsv是一个用纯Python编写的轻量级XML模式验证程序包(至少需要Python 2.4)。

so, it should work for you.

所以,它应该适合你。

I believe that ElementTree could also be used for that goal, but I am not 100% sure.

我相信ElementTree也可以用于这个目标,但我不是百分百肯定。

#2


1  

Why don't you try invoking an online XML validator and parsing the results?

为什么不尝试调用在线XML验证器并解析结果?

I couldn't find any free REST or SOAP based services but it would be easy enough to use a normal HTML form based one such as this one or this one. You just need to construct the correct request and parse the results (httplib may be of help here if you don't want to use a third party library such as mechanize to easy the pain).

我找不到任何免费的基于REST或SOAP的服务,但使用普通的HTML表单(例如这一个或这个)很容易。您只需要构造正确的请求并解析结果(如果您不想使用第三方库(例如mechanize)来解决问题,那么httplib可能会有所帮助)。

#3


1  

I haven't looked at it in a while so it might have changed, but Fourthought's 4Suite (community edition) could still be pure Python.

我有一段时间没有看过它,所以它可能已经改变了,但Fourthought的4Suite(社区版)仍然可以是纯Python。

Edit: just browsed through the docs and it's mostly Python which probably isn't enough for you.

编辑:只浏览文档,它主要是Python,可能对你来说还不够。

#4


0  

The beautifulsoup module is pure Python (and a single .py file), but I don't know if it will fulfill your validation needs, I've only used it for quickly extracting some fields on large XMLs.

beautifulsoup模块是纯Python(和单个.py文件),但我不知道它是否能满足您的验证需求,我只使用它来快速提取大型XML上的某些字段。

http://www.crummy.com/software/BeautifulSoup/

#1


4  

Do you mean something like MiniXsv? I have never used it, but from the website, we can read that

你的意思是MiniXsv吗?我从未使用过它,但是从网站上我们可以读到它

minixsv is a lightweight XML schema validator package written in pure Python (at least Python 2.4 is required).

minixsv是一个用纯Python编写的轻量级XML模式验证程序包(至少需要Python 2.4)。

so, it should work for you.

所以,它应该适合你。

I believe that ElementTree could also be used for that goal, but I am not 100% sure.

我相信ElementTree也可以用于这个目标,但我不是百分百肯定。

#2


1  

Why don't you try invoking an online XML validator and parsing the results?

为什么不尝试调用在线XML验证器并解析结果?

I couldn't find any free REST or SOAP based services but it would be easy enough to use a normal HTML form based one such as this one or this one. You just need to construct the correct request and parse the results (httplib may be of help here if you don't want to use a third party library such as mechanize to easy the pain).

我找不到任何免费的基于REST或SOAP的服务,但使用普通的HTML表单(例如这一个或这个)很容易。您只需要构造正确的请求并解析结果(如果您不想使用第三方库(例如mechanize)来解决问题,那么httplib可能会有所帮助)。

#3


1  

I haven't looked at it in a while so it might have changed, but Fourthought's 4Suite (community edition) could still be pure Python.

我有一段时间没有看过它,所以它可能已经改变了,但Fourthought的4Suite(社区版)仍然可以是纯Python。

Edit: just browsed through the docs and it's mostly Python which probably isn't enough for you.

编辑:只浏览文档,它主要是Python,可能对你来说还不够。

#4


0  

The beautifulsoup module is pure Python (and a single .py file), but I don't know if it will fulfill your validation needs, I've only used it for quickly extracting some fields on large XMLs.

beautifulsoup模块是纯Python(和单个.py文件),但我不知道它是否能满足您的验证需求,我只使用它来快速提取大型XML上的某些字段。

http://www.crummy.com/software/BeautifulSoup/