如何使用可变元素列表制作 XSD(参见说明)
How to make an XSD with list of variable elements(see description)
我需要制作一个 xsd 来验证一个 XML,它有一个包含私人和企业协会的列表。
我的 XSD 看起来像这样:
<xsd:element name="PartnerAssociationList" type="PartnerAssociationList_t"/>
<xsd:complexType name="PartnerAssociationList_t">
<xsd:sequence>
<xsd:choice>
<xsd:element name="PartnerPrivateAssociation" type="PartnerPrivateAssociation_t" maxOccurs="unbounded"/>
<xsd:element name="PartnerRetailAssociation" type="PartnerRetailAssociation_t" maxOccurs="unbounded"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
显然这段代码只允许 XML 中的一种关联发生,而我需要两者。我知道我可以做这样的事情
<xsd:complexType name="PartnerAssociationList_t">
<xsd:sequence>
<xsd:sequence>
<xsd:element name="Association" type="PartnerAssociation_t" maxOccurs="unbounded"/>
</xsd:sequence`enter code here`>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="PartnerAssociation_t">
<xsd:sequence>
<xsd:choice>
<xsd:element name="PartnerPrivateAssociation" type="PartnerPrivateAssociation_t"/>
<xsd:element name="PartnerRetailAssociation" type="PartnerRetailAssociation_t"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
但我不能在 XML 中添加额外的 "Association" 元素。
如果你想支持私人和零售协会的任何混合,那么你只需要删除 sequence
并使 choice
无界:
<xsd:complexType name="PartnerAssociationList_t">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="PartnerPrivateAssociation" type="PartnerPrivateAssociation_t"/>
<xsd:element name="PartnerRetailAssociation" type="PartnerRetailAssociation_t"/>
</xsd:choice>
</xsd:complexType>
您的版本允许在无限数量的私人协会或无限数量的零售协会之间进行单一选择,而我的版本允许无限数量的 "items",其中每个项目要么是私人的,要么是零售的。
我需要制作一个 xsd 来验证一个 XML,它有一个包含私人和企业协会的列表。 我的 XSD 看起来像这样:
<xsd:element name="PartnerAssociationList" type="PartnerAssociationList_t"/>
<xsd:complexType name="PartnerAssociationList_t">
<xsd:sequence>
<xsd:choice>
<xsd:element name="PartnerPrivateAssociation" type="PartnerPrivateAssociation_t" maxOccurs="unbounded"/>
<xsd:element name="PartnerRetailAssociation" type="PartnerRetailAssociation_t" maxOccurs="unbounded"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
显然这段代码只允许 XML 中的一种关联发生,而我需要两者。我知道我可以做这样的事情
<xsd:complexType name="PartnerAssociationList_t">
<xsd:sequence>
<xsd:sequence>
<xsd:element name="Association" type="PartnerAssociation_t" maxOccurs="unbounded"/>
</xsd:sequence`enter code here`>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="PartnerAssociation_t">
<xsd:sequence>
<xsd:choice>
<xsd:element name="PartnerPrivateAssociation" type="PartnerPrivateAssociation_t"/>
<xsd:element name="PartnerRetailAssociation" type="PartnerRetailAssociation_t"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
但我不能在 XML 中添加额外的 "Association" 元素。
如果你想支持私人和零售协会的任何混合,那么你只需要删除 sequence
并使 choice
无界:
<xsd:complexType name="PartnerAssociationList_t">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="PartnerPrivateAssociation" type="PartnerPrivateAssociation_t"/>
<xsd:element name="PartnerRetailAssociation" type="PartnerRetailAssociation_t"/>
</xsd:choice>
</xsd:complexType>
您的版本允许在无限数量的私人协会或无限数量的零售协会之间进行单一选择,而我的版本允许无限数量的 "items",其中每个项目要么是私人的,要么是零售的。