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.