Select Git revision
validator.py
Jörn Künsemöller authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
validator.py 980 B
from lxml import etree
import os
d = os.path.dirname(os.path.realpath(__file__))
def validate(xmlpath, xsdpath):
'''validates given xml file against given xsd file'''
with open(xsdpath) as xsd:
xmlschema_doc = etree.parse(xsd)
xmlschema = etree.XMLSchema(xmlschema_doc)
with open(xmlpath) as xml:
doc = etree.parse(xml)
valid = xmlschema.validate(doc)
if not valid:
try:
xmlschema.assertValid(doc)
except Exception as err:
print err
return valid
#expose a main method in this lib module which can be used by external programs
#or by the bin/validatesip 'program'
def main(xml):
#do the proper calls to the SIP API
# parse cmdline args etc
try:
xml = xml
xsd = d+"/LTA-SIP.xsd"
return validate(xml, xsd)
except Exception as err:
print "An error occurred:"
print err