Created
March 4, 2021 18:02
-
-
Save brackendev/616ffd4f4d0203f0d2844a967a7f4de9 to your computer and use it in GitHub Desktop.
Validate XML file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
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) | |
exit 0 | |
except Exception as e: | |
print("%s is NOT well-formed! %s" % (filename, e)) | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment