- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 XML::LibXML::Schema 针对 xsd 验证 xml 文件。问题是,如果我的 xml 有多个语义问题,则验证将在第一个问题上消失,而不会报告其他问题。
It finds the first error, no reference to <foobar/>
bash-3.2$ ./test.pl test.xsd test.xml
xmlfile <test.xml>
failed validation: test.xml:14: Schemas validity error : Element 'foobar': This element is not expected.
After I remove the first error, it finds another. "ten" is not an unsigned int
xmlfile <test.xml>
failed validation: test.xml:11: Schemas validity error : Element 'allocation': 'ten' is not a valid value of the atomic type 'xs:unsignedInt'.
Changing "ten" to 10 fixes this issue
bash-3.2$ ./test.pl test.xsd test.xml
No issues found
xsd:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- channel -->
<xsd:element name="channel">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="username" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<!-- hotel -->
<xsd:element name="hotel">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="date">
<xsd:complexType>
<xsd:attribute name="from" use="required" type="xsd:string" />
<xsd:attribute name="to" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element ref="room" minOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsd:unsignedInt" />
</xsd:complexType>
</xsd:element>
<!-- room -->
<xsd:element name="room">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="allocation" type="xsd:unsignedInt"></xsd:element>
</xsd:sequence>
<xsd:attribute name="id" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<!-- building all together -->
<xsd:element name="request">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="channel" maxOccurs="1"/>
<xsd:element ref="hotel" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="type" use="required" type="xsd:string" />
</xsd:complexType>
</xsd:element>
xml:
<?xml version="1.0" encoding="UTF-8"?>
<request type="test" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<channel name="channel">
<username>user</username>
<password>pass</password>
</channel>
<hotel id="ten">
<date from="2009-07-07" to="2009-07-17"/>
<room id="1">
<allocation>ten</allocation>
</room>
</hotel>
</request>
perl 脚本:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
#use Carp;
use vars qw( $xsd $xml $schema $parser $doc );
use XML::LibXML;
#
# MAIN
#
my $xsd = $ARGV[0];
my $xml = $ARGV[1];
$schema = XML::LibXML::Schema->new(location => $xsd);
$parser = XML::LibXML->new;
$doc = $parser->parse_file($xml);
eval { $schema->validate($doc) };
if ( $@ ) {
warn "xmlfile <$xml> failed validation: $@" if $@; exit(1);
}
else { print "No issues found\n"; }
最佳答案
尝试通过 recover => 1
至XML::LibXML->new
.它可能会有所帮助。
来自 XML::LibXML::Parser 的文档...
recover
/parser, html, reader/
recover from errors; possible values are 0, 1, and 2
A true value turns on recovery mode which allows one to parse
broken XML or HTML data. The recovery mode allows the parser to
return the successfully parsed portion of the input document. This
is useful for almost well-formed documents, where for example a
closing tag is missing somewhere. Still, XML::LibXML will only
parse until the first fatal (non-recoverable) error occurs,
reporting recoverable parsing errors as warnings. To suppress even
these warnings, use recover=>2.
Note that validation is switched off automatically in recovery
mode.
关于xml - Perl XML::LibXML::Schema 将在第一个错误时停止验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3206672/
我已经下载了草莓 PERL 并在 Winxp sp3 上使用 CGI Perl Apache 编写了一个应用程序。我使用的库之一(由其他人编写)使用 XML::LibXML。当我加载页面时,它给出内部
libxml 在 libxml.h 中使用以下代码行,但它不与 libxml 捆绑在一起。 #include "config.h" 我正在尝试在 Swift 中使用 XMPPFramework for
我知道这个问题经常出现,但我查看了所有其他答案,但没有一个与我相关。 我正在尝试从源代码编译神经成像软件 FSL(我必须这样做,我的 Linux 发行版不支持它)。我已按照所有说明进行操作 liste
当我运行 cyrus-imapd-2.4.17-caldav-beta9 时出现以下错误: In file included from httpd.c:68:0: httpd.h:48:25: fat
我熟悉 XML,已经将它用于一些简单的用途。但是,我被要求创建一个自定义解决方案(必须使用 Perl)来向 AuthorizeNet 的网关提交付款。 AuthNet 不提供对 Perl 的支持,所以
我有一个示例 Perl 脚本,我试图根据模式加载和验证文件,它们询问各种节点。 #!/usr/bin/env perl use strict; use warnings; use XML::LibXM
我有我正在迭代的非常大的 XML 文档。 XML 主要使用属性而不是节点值。我可能需要在文件中找到许多节点来拼凑一组信息。它们通过不同的 ref 标签值联系在一起。目前,每次我需要定位其中一个节点以从
我正在使用 XML::LibXML,我想添加一条注释,使注释位于标签之外。甚至可以把它放在标签外面吗?我试过 appendChild,insertBefore |之后,没有区别... jun
我正在使用 XML::LibXML,我想添加一条注释,使注释位于标签之外。甚至可以把它放在标签外面吗?我试过 appendChild,insertBefore |之后,没有区别... jun
我正在尝试使用 ISO-8859-1 中的 libxml2 编写 XML 文件。但从文档看来,对于我创建的每个文本节点,我都必须转换为 UTF-8,这是 libxml 的内部编码。然后,当调用 xml
我正在尝试用 C++ 解析 XML 文档。我没有与文档关联的任何形式的元数据。由于我是 XML 的新手,所以我想了解解析此 xml 的最佳方法。我正在使用 libxml2 来实现这一点。 我目前正在做
使用 libxml2 两天后我就遇到了一个问题,这让我很烦。 基本上,我使用套接字通过网络发送一个 xml 缓冲区。当我在服务器上收到它并尝试解析它时,它说: parser error : Input
我正在使用 libxml 的 HTML 解析器来创建 html 文档的 dom 树。 libxml 将每个节点的文本内容作为一个整体字符串(节点)给出,但我的要求是进一步拆分每个文本节点的空格并创建尽
我已经开始在 C 中使用 libxml,并且正在使用 xmlXPathEvalExpression 函数来计算 XPath。 我的 XML 文件实际上代表一个表,每个子节点代表该表中的一行,其属性是对
我有一个可以通过终端运行的源文件 gcc source.c -I/usr/include/libxml2 -lxml2 -o output 但是当我 #include 包含 libxml 源文件的源文
这里似乎有些奇怪。 在下面的示例中,我通过 XPath 查询 ( //book/isbn/text() ) 访问文本节点。 text()有必要强制XML::LibXML允许我使用 XML::LibXM
我有一个 XML 文件,如下 示例.xml test 以下代码未找到 id 标记值: use XML::LibXML; my $filename = 'example.xml'; my
我正在与 XML::LibXML 一起工作在 Perl 中。 假设我有两个 $element由不同(不透明)XPath 查询获得的引用。 (如何)我可以确定,如果两个$element (节点)refs
我有一个问题,我肯定可以使用一些帮助。首先,要温柔。我是 perl 和 LibXML 的新手。我一直在解析文档并将元素放入一个数组中,然后将其写入电子表格列。在测试过程中发现一些节点有多个同名的子节点
在我的一生中,我无法找出正确的代码来访问我的 XML 文件中的注释行。我是否使用 findnodes , find , getElementByTagName (怀疑)。 我是否正确假设这些评论行是可
我是一名优秀的程序员,十分优秀!