根据我的自定义架构验证 XML 文件
我正在尝试学习 XML,并且我已经提出了一个架构和示例文件示例,以了解在深入了解之前我是否知道自己在做什么。
.xsd 文件
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Assumption" type="assumptionType"/>
<xsd:complexType name="assumptionType">
<xsd:sequence>
<xsd:element name="entries" type="entriesType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="entriesType">
<xsd:sequence>
<xsd:element name="entry">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="x" type="xsd:decimal"/>
<xsd:element name="y" type="xsd:decimal"/>
<xsd:element name="value" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<Assumption>
<entries>
<entry>
<x>12</x>
<y>14</y>
<value>16</value>
</entry>
<entry>
<x>12</x>
<y>24</y>
<value>5</value>
</entry>
</entries>
</Assumption>
我正在使用 此工具 尝试根据 .xsd 验证 .xml 。我收到以下错误:
The following errors were found:
TYPE LOC MESSAGE
Validation 9, 10 cvc-complex-type.2.4.d: Invalid content was found starting
with element 'entry'. No child element is expected at this point
我显然不明白某些事情。
I am trying to learn XML, and I have come up with a schema and sample file example to see if I know what I'm doing before I get to far.
.xsd file
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Assumption" type="assumptionType"/>
<xsd:complexType name="assumptionType">
<xsd:sequence>
<xsd:element name="entries" type="entriesType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="entriesType">
<xsd:sequence>
<xsd:element name="entry">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="x" type="xsd:decimal"/>
<xsd:element name="y" type="xsd:decimal"/>
<xsd:element name="value" type="xsd:decimal"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
.xml file
<?xml version="1.0" encoding="UTF-8"?>
<Assumption>
<entries>
<entry>
<x>12</x>
<y>14</y>
<value>16</value>
</entry>
<entry>
<x>12</x>
<y>24</y>
<value>5</value>
</entry>
</entries>
</Assumption>
I am using this tool to try to validate the .xml against the .xsd. I am getting the following error:
The following errors were found:
TYPE LOC MESSAGE
Validation 9, 10 cvc-complex-type.2.4.d: Invalid content was found starting
with element 'entry'. No child element is expected at this point
I'm obviously not understanding something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
entry
是多个节点,因此您需要指定maxOccurs="unbounded"
您的 XSD 将为:-
Since
entry
is multiple node, you need to specifymaxOccurs="unbounded"
Your XSD would be:-