import time from lxml import etree xml_in = ' /DBQAAAAAAAA///wFAUAAAfRf+/+T/iBBX4AUmXAAAEBAQArAQpDVUVJPJ8jKjAwAh1DVUVJAAAH0X//AABScXoBCTExMzYzNTIyMTYAAB+wVcY= ' #xml_in = ' mag2-mx5-suits /DAlAH+DGqLsAP///wUAH2gIAOCABUFDVYAAUmXAAAAAAAAAV7AxRg== ' xml_in = xml_in.encode('ascii') def validate(xml_path: str, xsd_path: str) -> bool: xmlschema_doc = etree.parse(xsd_path) xmlschema = etree.XMLSchema(xmlschema_doc) result = False try: xml_doc = etree.XML(xml_in) except Exception as inst: print(inst) return result try: xmlschema.assertValid(xml_doc) print('XML valid, schema validation ok.') result = True except etree.DocumentInvalid as err: print("ERROR:" + str(type(err))) print("ERROR:" + str(err)) print("ERROR:" + str(dir(err))) print("ERROR:" + str(err.error_log)) print("dddddddddddddddddddddddddd") for error in xmlschema.error_log: print(str(dir(error))) print(error.path) print(error.message) except Exception as ex: print(str(ex)) ##result = xmlschema.validate(xml_doc) return result tic = time.perf_counter() if validate(xml_in, "./schema/OC-SP-ESAM-API-I03-Signal.xsd"): #if validate("./test.xml", "./OC-SP-ESAM-API-C01-Signal.xsd"): #if validate(xml_in, "./SCTE35.xsd"): #if validate("./test.xml", "./MD-SP-CORE-C01.xsd"): print('Valid! :)') else: print('Not valid! :(') toc = time.perf_counter() print(f"Downloaded the tutorial in {toc - tic:0.4f} seconds")