如何为 xmllint 设置目录文件?

Pau*_*Cbr 5 xml xsd lint xml-validation

好的。我想为 xmllint 设置目录文件来解决问题,以便从本地文档验证 dcterms xml 命名空间。我相信我已经做对了一切,但它似乎根本不起作用。

我正在运行 OSX。

我已经创建了一个目录 /etc/xml

$ mkdir /etc/xml
$ cd /etc/xml
Run Code Online (Sandbox Code Playgroud)

我已将 dcterms.xsd 下载到该目录

$ ls -l
-rw-r--r--  1 ibis  wheel  12507 24 Jul 11:42 dcterms.xsd
Run Code Online (Sandbox Code Playgroud)

我创建了一个名为“目录”的文件

$ xmlcatalog --create > catalog
Run Code Online (Sandbox Code Playgroud)

我已将 dcterms 命名空间添加到目录文件中

$ xmlcatalog --noout --add uri http://purl.org/dc/elements/1.1/ file:///etc/xml/dc.xsd
$ xmlcatalog --noout --add uri http://purl.org/dc/terms/ file:///etc/xml/dcterms.xsd
$ cat catalog
<?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://purl.org/dc/elements/1.1/" uri="file:///etc/xml/dc.xsd"/>
  <uri name="http://purl.org/dc/terms/" uri="file:///etc/xml/dcterms.xsd"/>
</catalog>
Run Code Online (Sandbox Code Playgroud)

在工作目录中,我创建了一个名为 Empty.xsd 的简单 xml 模式

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Empty" xmlns:tns="http://www.example.org/Empty" elementFormDefault="qualified">
  <element name="empty">
    <complexType>
      <sequence>
        <any processContents="strict" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <anyAttribute></anyAttribute>
    </complexType>
  </element>
</schema>
Run Code Online (Sandbox Code Playgroud)

请注意,processcontnts 是“严格的”。

我创建了一个应该触发所有验证的 XML 文件:

<?xml version="1.0" encoding="UTF-8"?>
<empty xmlns="http://www.example.org/Empty" 
          xmlns:dcterms="http://purl.org/dc/terms/">
    <dcterms:title>A title</dcterms:title>
</empty>
Run Code Online (Sandbox Code Playgroud)

然后我尝试验证它。

$ xmllint --noout --valid --schema Empty.xsd Empty.xml
Empty.xml:2: validity error : Validation failed: no DTD found !
y xmlns="http://www.example.org/Empty" xmlns:dcterms="http://purl.org/dc/terms/"
                                                                               ^
Empty.xml:3: element title: Schemas validity error : Element '{http://purl.org/dc/terms/}title': No matching global element declaration available, but demanded by the strict wildcard.
Empty.xml fails to validate
Run Code Online (Sandbox Code Playgroud)

我已经按照文档中的说明设置了一个目录,并将其指向本地 dcterms 架构文件。为什么 xmllint 找不到它?

Jar*_*zek 2

  1. 我的 中没有title元素dcterms,所以我将其替换为abstract
  2. 我找不到任何确认信息,但其他人也报告了在 libxml 中使用 xsd 架构的目录文件的问题。我发现目录对于 dtds 来说工作正常。
  3. 有一个解决方法。插入。<import namespace="http://purl.org/dc/terms/" schemaLocation="dcterms.xsd" />Empty.xsd之后我就删除了No matching global消息。
  4. No DTD found仍然可见,但返回码从 3 增加到 4,这意味着解析成功。
  5. 编辑:--sax开关似乎对“未找到 DTD”消息有帮助。

相关问题:Xmlvalidation with schema header and Catalog Lookup,没有答案。这就是第 2 点。