我需要为我们将在系统之间使用的 XML 文件生成 XSD,以便我们可以验证我们获得的数据是否有效。
XML 看起来像这样(但有更多字段):
<Request>
<Request_ID>1000012295</Request_ID>
<Extra_Info>
<Item>
<Item_Number>0000000001</Item_Number>
<ItemDescription>test- 2</ItemDescription>
</Item>
<Item>
<Item_Number>0000000002</Item_Number>
<ItemDescription>test - 2</ItemDescription>
</Item>
</Extra_Info>
</Request>
我的 XSD 如下:
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Request">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Request_ID" type="xsd:int" />
<xsd:element name="Extra_Info">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Item">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Item_Number" type="xsd:int" />
<xsd:element name="ItemDescription" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
当我只有一个Item
节点时,此模式有效,但一旦我有多个节点,我就会收到以下错误:
元素“Extra_Info”具有无效的子元素“Item”。
如果将其指定为序列,为什么它不起作用?
谢谢!
PS:我使用This Online Validator进行快速验证,但使用 XMLReader 时也遇到同样的错误