问题
How to validate xml (using libxml) file without specifying the schema file explicitly? xsd file is in the header of the xml file. The corresponding xsd file URL should be located in the local file system using a Catalog.xml.
回答1:
Looks like it is not possible at the moment (libxml 2.8.0). This is taken from libxml page (xmlschemas):
interface to the XML Schemas handling and schema validity checking, it is incomplete right now.
As a workaround one may use a combined schema with lots of import
elements. Superfluous namespaces may be specified. Finally the combined schema must be passed to the validator explicitly.
Namespaces imported with xsd:import
are resolved correctly using catalogs, unless schemaLocation
in import
specifies valid direct location.
<import namespace="http://example.com"
schemaLocation="example.xsd">
If example.xsd
does not exist in current directory, it is resolved using catalog files.
来源:https://stackoverflow.com/questions/7994086/xml-validation-with-schema-header-and-catalog-lookup