How to set up catalog files for xmllint?

拈花ヽ惹草 提交于 2019-12-04 11:09:44
Jarekczek
  1. I don't have title element in the dcterms, so I replaced it with abstract
  2. I can't find any confirmation, but other people also report problems with using catalog files for xsd schemas in libxml. I found catalogs working ok for dtds though.
  3. There is a workaround. Insert <import namespace="http://purl.org/dc/terms/" schemaLocation="dcterms.xsd" /> into Empty.xsd. After that I got rid of No matching global message.
  4. No DTD found is still visible, but the return code increased from 3 to 4 and that means kind of successful parse.
  5. EDIT: --sax switch seems to help for "No DTD found" message.

Related question: Xml validation with schema header and Catalog lookup, no answer. That's about point 2.

Program xmllint doesn't auto-load XSD-files based on xmlns="something" attributes found in the to-be-parsed XML-file, it only uses the XSD specified in --schema parameter (and the ones imported/included from that).

For the test, you could create a NonEmpty.xsd like this:

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/Empty"
    elementFormDefault="qualified">
  <include schemaLocation="Empty.xsd"/>
  <import schemaLocation="dcterms.xsd" namespace="http://purl.org/dc/terms/"/>
</schema>

Usage:

$ xmllint -debugent -noout -schema NonEmpty.xsd Empty.xml
new input from file: NonEmpty.xsd
new input from file: Empty.xsd
new input from file: dcterms.xsd
new input from file: http://www.w3.org/2001/03/xml.xsd
new input from file: dc.xsd
new input from file: dcmitype.xsd
new input from file: Empty.xml
Empty.xml validates

Now with catalog file:

<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
  <uri name="http://www.w3.org/2001/03/xml.xsd"          uri="file:///home/zsiga/proba/dcterms/2001_03_xml.xsd"/>
  <uri name="http://dublincore.org/schemas/xmls/qdc/dcterms.xsd" uri="file:///home/zsiga/proba/dcterms/dcterms.xsd"/>
</catalog>

Here's the NonEmpty2.xsd file:

<?xml version="1.0" encoding="UTF-8"?>
<schema 
    xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/Empty"
    elementFormDefault="qualified">
  <include schemaLocation="Empty.xsd"/>
  <import schemaLocation="http://dublincore.org/schemas/xmls/qdc/dcterms.xsd" namespace="http://purl.org/dc/terms/"/>
</schema>

And its usage:

$ XML_CATALOG_FILES=./catalog xmllint -debugent -noout \
    -schema NonEmpty2.xsd Empty.xml
new input from file: NonEmpty2.xsd
new input from file: Empty.xsd
new input from file: file:///home/zsiga/proba/dcterms/dcterms.xsd
new input from file: file:///home/zsiga/proba/dcterms/2001_03_xml.xsd
new input from file: file:///home/zsiga/proba/dcterms/dc.xsd
new input from file: file:///home/zsiga/proba/dcterms/dcmitype.xsd
new input from file: Empty.xml
Empty.xml validates
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!