def validate_xml_file_against_xsd(xml_file, xsd_file): try: xml_doc = parse(xml_file) xsd_doc = parse(xsd_file) xmlschema = XMLSchema(xsd_doc) xmlschema.assert_(xml_doc) logger.info("XSD Pass!") except Exception as e: logger.info("XSD Fail!") BuiltIn().fail(e)
def xml_to_xsd_validation(file_xml, file_xsd): """ Verify that the XML compliance with XSD Arguments: 1. file_xml: Input xml file 2. file_xsd: xsd file which needs to be validated against xml Return: No return value """ try: print_info("Validating:{0}".format(file_xml)) print_info("xsd_file:{0}".format(file_xsd)) xml_doc = parse(file_xml) xsd_doc = parse(file_xsd) xmlschema = XMLSchema(xsd_doc) xmlschema.assert_(xml_doc) return True except XMLSyntaxError as err: print_error("PARSING ERROR:{0}".format(err)) return False except AssertionError as err: print_error("Incorrect XML schema: {0}".format(err)) return False