Skip to content

Instantly share code, notes, and snippets.

@pbertera
Created January 20, 2015 13:28
Show Gist options
  • Save pbertera/57d2b8721d8ef9cd67bb to your computer and use it in GitHub Desktop.
Save pbertera/57d2b8721d8ef9cd67bb to your computer and use it in GitHub Desktop.
Usage: pyxmlvalidator.py file1.xml file2.xml ...
#!/usr/bin/python
from xml.sax.handler import ContentHandler
from xml.sax import make_parser
from glob import glob
import sys
def parsefile(file):
parser = make_parser()
parser.setContentHandler(ContentHandler())
parser.parse(file)
for arg in sys.argv[1:]:
for filename in glob(arg):
try:
parsefile(filename)
print "%s is well-formed" % filename
except Exception, e:
print "%s is NOT well-formed! %s" % (filename, e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment