Xml validation with schema header and Catalog lookup

回眸只為那壹抹淺笑 提交于 2019-12-07 20:05:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!