如何构建模式以验证可以包含组内标记的单个和多个实例的xml?
CO和AS中的标签可以按任何顺序出现(删除序列作为选项)。 CUST.NAME,FED.ID和CUST.ADDRESS1只能在CO中出现一次.AS是无界的(删除所有选项)。 实施例
<FormData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Stack.xsd">
<CO>
<CUST.NAME>mlb2</CUST.NAME>
<FED.ID></FED.ID>
<CUST.ADDRESS1>abc st</CUST.ADDRESS1>
<AS>
<EQUIP.COST>1.00</EQUIP.COST>
<EQUIP.DESC>asDesc</EQUIP.DESC>
<MODEL>UpdFromUDAction</MODEL>
</AS>
<AS>
<EQUIP.COST>1.00</EQUIP.COST>
<EQUIP.DESC>asDesc</EQUIP.DESC>
<MODEL>UpdFromUDAction</MODEL>
</AS>
</CO>
</FormData>
这是我到目前为止的模式,但如果存在重复的CUST.NAME,FED.ID或CUST.ADDRESS1标记,它不会失败。 使用
<xsd:choice maxOccurs="unbounded">
在COType中,因为可能存在其他几个标记(例如CUST.ZIP)。 架构:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsd:simpleType name="CO.FED.IDType">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="CO.CUST.NAMEType">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="150" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="CO.CUST.ADDRESS1Type">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="AS.EQUIP.COSTType">
<xsd:restriction base="xsd:decimal">
<xsd:totalDigits value="14" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="AS.EQUIP.DESCType">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="AS.MODELType">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="COType">
<xsd:choice maxOccurs="unbounded">
<xsd:element name="FED.ID" type="CO.FED.IDType" minOccurs="0" nillable="true" maxOccurs="1" />
<xsd:element name="CUST.NAME" type="CO.CUST.NAMEType" minOccurs="0" nillable="true" maxOccurs="1" />
<xsd:element name="CUST.ADDRESS1" type="CO.CUST.ADDRESS1Type" minOccurs="0" nillable="true" maxOccurs="1" />
<xsd:element name="AS" type="ASType" minOccurs="0" maxOccurs="unbounded" />
</xsd:choice>
</xsd:complexType>
<xsd:complexType name="ASType">
<xsd:all>
<xsd:element name="MODEL" type="AS.MODELType" minOccurs="0" nillable="true" maxOccurs="1" />
<xsd:element name="EQUIP.COST" type="AS.EQUIP.COSTType" minOccurs="0" nillable="true" maxOccurs="1" />
<xsd:element name="EQUIP.DESC" type="AS.EQUIP.DESCType" minOccurs="0" nillable="true" maxOccurs="1" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="FormDataType">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element name="CO" type="COType" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="FormData" type="FormDataType" />
</xsd:schema>