问题描述
好的.我想为xmllint设置目录文件以解决问题,以便从本地文档验证dcterms xml命名空间.我相信我做对了所有事情,但是似乎根本行不通.
Ok. I want to set up catalog files for xmllint to fix things so that the dcterms xml namespace is validated from a local document. I believe that I have done everything right, but it simply doesn't seem to be working.
我正在运行OSX.
我已经创建了目录/etc/xml
I have created a directory /etc/xml
$ mkdir /etc/xml
$ cd /etc/xml
我已将dcterms.xsd下载到该目录
I have downloaded dcterms.xsd to that directory
$ ls -l
-rw-r--r-- 1 ibis wheel 12507 24 Jul 11:42 dcterms.xsd
我创建了一个名为"catalog"的文件
I have created a file named "catalog"
$ xmlcatalog --create > catalog
我已将dcterms命名空间添加到目录文件中
I have added the dcterms namespace to the catalog file
$ 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>
在工作目录中,我创建了一个简单的xml模式,名为Empty.xsd
In a work directory, I have created a simple xml schema named Empty.xsd
<?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>
请注意,过程内容是严格的".
Note that the processcontnts is "strict".
我已经创建了一个XML文件,该文件应该触发所有验证:
I have created an XML file which should trigger all the validation:
<?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>
然后我尝试对其进行验证.
Then I attempt to validate it.
$ 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
我已经按照文档中的指定建立了目录,并将其指向本地dcterms模式文件.为什么xmllint找不到它?
I have set up a catalog as specified in the docs and pointed it at the local dcterms schema file. Why does xmllint fail to find it?
推荐答案
- 我在
dcterms
中没有title
元素,因此我将其替换为abstract
- 我找不到任何确认,但是其他人也报告了在libxml中将目录文件用于xsd模式的问题.我发现目录对于dtds来说还可以.
- 有一种解决方法.将
<import namespace="http://purl.org/dc/terms/" schemaLocation="dcterms.xsd" />
插入Empty.xsd
.之后,我摆脱了No matching global
消息. -
No DTD found
仍然可见,但是返回码从3增加到4,这意味着可以成功解析. --sax
开关似乎有助于未找到DTD"消息.
- I don't have
title
element in thedcterms
, so I replaced it withabstract
- 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.
- There is a workaround. Insert
<import namespace="http://purl.org/dc/terms/" schemaLocation="dcterms.xsd" />
intoEmpty.xsd
. After that I got rid ofNo matching global
message. No DTD found
is still visible, but the return code increased from 3 to 4 and that means kind of successful parse.-
--sax
switch seems to help for "No DTD found" message.
相关问题:具有架构标头和目录查找的Xml验证一个>,没有答案.大约是第2点.
Related question: Xml validation with schema header and Catalog lookup, no answer. That's about point 2.
这篇关于如何设置xmllint的目录文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!