我正在Visual Studio 2010中编写XSD模式文件。我想定义一个不需要的复杂类型,并且在xml中有无限的整体。我使用了minOccurs和maxOccurs属性,但我在编辑器中得到一个错误,这些属性(minOccurs/maxOccurs)是不允许的。我可以将它们添加到简单类型中,但不能添加到复杂类型中。如何定义一个复杂类型可以有0到多次出现?
这是我使用的xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="patient" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
这应该仍然是有效的XSD语法。VS编辑器只是突出显示它,并告诉你这是不允许的吗?它可能只是报告错误。
编辑:哦,你需要一个复杂类型的序列!<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="patients">
<xs:complexType>
<xs:sequence>
<xs:element name="patient" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:elemennt>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>