如何在gentoo中针对.dtd验证metadata.xml? [英] How to validate metadata.xml against .dtd in gentoo?
问题描述
我正在尝试验证元数据. xml 与 www.gentoo.org/dtd/metadata相对. dtd 和
I am trying to validate metadata.xml against www.gentoo.org/dtd/metadata.dtd with xmllint from =dev-libs/libxml2-2.9.3 ebuild.
我尝试了这些命令(来自此处):
I tried the commands (some from here):
$ xmllint --noout --valid metadata.xml
error : Unknown IO error
metadata.xml:2: warning: failed to load external entity "http://www.gentoo.org/dtd/metadata.dtd"
与xmllint metadata.xml --dtdvalid metadata.dtd
相同
和xmllint --loaddtd http://www.gentoo.org/dtd/metadata.dtd
the same for xmllint metadata.xml --dtdvalid metadata.dtd
and xmllint --loaddtd http://www.gentoo.org/dtd/metadata.dtd
$ xmllint --valid metadata.xml --schema metadata.dtd
metadata.dtd:1: parser error : StartTag: invalid element name
我需要xmllint而不是 mono-xmltool (的https://stackoverflow.com/questions/1658325>),因为repoman -d
命令中使用了xmllint. repoman用于travis-ci中的gentoo覆盖验证
I need xmllint and not mono-xmltool (from C#/CLI) because xmllint is used in repoman -d
command. And repoman is used for gentoo overlay validation in travis-ci
如何使用xmllint正确验证xml?
How to validate xml with xmllint properly?
UPD: 网站返回"HTTP/1.1 301永久移动",这就是加载失败的原因
UPD: site returns "HTTP/1.1 301 Moved Permanently" and that is why load fails
strace的一部分:
part of strace:
recvfrom(3, "HTTP/1.1 301 Moved Permanently\r\n"..., 4096, 0, NULL, NULL) = 446
recvfrom(3, "", 4096, 0, NULL, NULL) = 0
close(3) = 0
write(2, "error : ", 8error : ) = 8
write(2, "Unknown IO error\n", 17Unknown IO error
libxml2可能不执行https
probably libxml2 doesn't do https
USE="icu ipv6 python readline -debug -examples -lzma -static-libs {-test}"
libxml2使用nanoHTTP, nanoHTTP可以与HTTPS一起使用
libxml2 uses nanoHTTP, nanoHTTP can work with HTTPS
推荐答案
您的假设是正确的,问题出在HTTPS上.要解决此问题并节省一些带宽和时间,repoman
会针对本地文件进行验证,如果找不到该文件,则会将其预取.默认位置为REPO_ROOT/metadata/dtd/metadata.dtd
或DISTDIR/metadata.dtd
.要获取repoman
用于xmllint
的确切参数,您必须查看其源代码-
Your assumption was right, the problem is HTTPS. To work around this and to save some BW and time, repoman
validates against a local file, which it prefetches if not found. The default location is either REPO_ROOT/metadata/dtd/metadata.dtd
or DISTDIR/metadata.dtd
. To get the exact arguments repoman
uses for xmllint
you have to have a look at its source code - here. As you can see, it's
xmllint --nonet --noout --dtdvalid <metadata.dtd> metadata.xml
此命令仍输出:
metadata.xml:2: warning: failed to load external entity "https://www.gentoo.org/dtd/metadata.dtd"
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
或使用HTTP:
I/O error : Attempt to load network entity http://www.gentoo.org/dtd/metadata.dtd
metadata.xml:2: warning: failed to load external entity "http://www.gentoo.org/dtd/metadata.dtd"
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
但仅作为警告,因此命令以0退出.
But only as a warning, so the command exits with 0.
这篇关于如何在gentoo中针对.dtd验证metadata.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!