I run this check with lxml:
parser = etree.XMLParser() try: root = etree.fromstring(xml_content.strip(), parser) except Exception as e: raise XMLFormatException(str(e), XMLFormatException.IN_XML) try: schema = etree.XMLSchema(etree.XML(xsd_content.strip())) except Exception as e: raise XMLFormatException(str(e), XMLFormatException.IN_XSD) if not schema.validate(): raise XMLValidationException("Se produjo un error al validar el XML", schema.error_log)
Suppose xml_content
and xsd_content
are created correctly. Part of the contents of xsd is this:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" elementFormDefault="qualified"> <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" /> </xsd:schema>
When I run the script, I get an error message:
Failed to load external object "xmldsig-core-schema.xsd"
When I hit http://www.w3.org/2000/09/xmldsig# in a browser, I get the contents of xsd.
Q : What am I missing here? How to avoid such an error?
Change Notes:
- This error occurs before validation can be performed (i.e., this error occurs in the XMLSchema constructor).
- The xsd file is provided from an external source and I am not allowed to edit it.
source share