【发布时间】:2014-03-08 11:59:48
【问题描述】:
我正在尝试根据 xsd 文件验证 xml 文件 但我得到一个错误,我不知道为什么 有人有想法吗?
我的 xsd 文件:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="call"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="cl">
<xs:complexType>
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element ref="arguments"/>
<xs:element ref="outputs"/>
</xs:choice>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="module" type="xs:string" use="required"/>
<xs:attribute name="title" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref=""/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
xs:element ref=""/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
我收到“无效文件”,但我看不出问题出在哪里,谁能帮帮我? 谢谢你
【问题讨论】:
-
我相信 Python 代码不是回答您的问题所必需的(因此您实际上可以删除它,以及
python标签。)验证错误是:cvc-complex-type.2.4.d: Invalid content was found starting with element 'outputs'. No child element is expected at this point.您可以更改您的打印解析器错误的代码,而不是invalid file,它不会提供有关错误的信息。 -
如何更改我的代码以打印我不明白的解析器错误你能解释更多吗? @helderdarocha
-
我使用的 PHP 不多,但我相信您必须以某种方式访问 LibXMLError 才能打印消息。我找到了this article,如果您有兴趣,它可能会有所帮助(它有一个关于解析器错误报告的部分)
-
您的架构文档似乎无效(除了由 holderdarocha 确定的问题之外):您有四个名称为空的元素声明。