views:

469

answers:

4

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?

+1  A: 

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

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).

jkp
+4  A: 

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

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

so, it should work for you.

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

Roberto Liffredo
Perfect, that's exactly what I was looking for.
Simon Willison
+1  A: 

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.

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

Van Gale
A: 

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.

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

juanjux