Search code examples
cvalidationxsdlibxml2

Validating an XML document fails to load schemas referenced with relative paths from within original XSD document


If I start with xmlSchemaNewParserCtxt() the parser is fine and finds all referenced schemas, but I wonder if I can somehow tell it where the schemas are if I use xmlSchemaNewMemParserCtxt().

The thing is, If I already have downloaded XSD in memory can I pass the document URL to the parser so it finds related stuff?

a)

char *urlPath = "http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd";
xmlSchemaNewParserCtxt (urlPath);

b)

xmlSchemaNewMemParserCtxt (schemaBuffer, buffSize);

Variant a) works fine, variant b) produces error I/O warning : failed to load external entity "../common/UBL-CommonAggregateComponents-2.1.xsd"

Schemas are located here: http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd


Solution

  • The best solution is probably to use XML catalogs, but you can also control loading of sub-resources with xmlRegisterInputCallbacks or xmlSetExternalEntityLoader.