我有像ParcelNumber
或像CoordinateX
或CoordinateY
這樣的座標強制要求的這樣的要求,並且這兩個包含不同的XML層次結構。因此,如果輸入xml包含宗地編號,它應該返回成功,或者如果它包含兩個座標,那麼它應該返回成功。我創建了以下模式,如果我只發送宗地編號,它將返回成功,但是如果我發送Co-座標它會失敗,它要求發送包裹數量被wrong.How實現it.In果殼我有以下問題如何在XML模式中強制使用任一字段
1>If i send both coordinates and no parcel number it should return success
2>IF i send x coordinate then it should fail and ask to send Y co ordinate
以下是我迄今所做
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:element name="NOCPlantMapRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Applicationtype" minOccurs="0" type="xsd:string"/>
<xsd:element name="RelatedNOCRefNumber" minOccurs="0" type="xsd:string"/>
<xsd:element name="WorkLocation" minOccurs="1" maxOccurs="1" type="LocationType"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="LocationType">
<xsd:all>
<xsd:element name="ParcelNumber" type="ParcelNumberType" maxOccurs="1"/>
<xsd:element name="WorkArea" type="WorkAreaType" maxOccurs="1"/>
<xsd:element name="Roads" type="RoadListType" maxOccurs="1"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="RoadListType">
<xsd:sequence>
<xsd:element name="WorkLocationRoad" type="WorkLocationRoadType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="WorkLocationRoadType">
<xsd:sequence>
<xsd:element name="RoadName" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="CommunitiesListType">
<xsd:sequence>
<xsd:element name="WorkLocationRoad" type="WorkLocationRoadType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="ParcelNumberType">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:complexType name="WorkAreaType">
<xsd:sequence>
<xsd:element name="WorkArea" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Coordinates" minOccurs="1" type="CoordinatesType"/>
<xsd:element name="Communities" type="CommunitiesListType" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="CoordinatesType">
<xsd:sequence>
<xsd:element name="WorkLocationCoordinate" type="WorkLocationCoordinateType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="WorkLocationCoordinateType">
<xsd:sequence>
<xsd:element name="CoordinateX" type="xsd:string"/>
<xsd:element name="CoordinateY" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
編輯 任何有關如何正確使用choice
的想法
如果這個問題是關於XML模式,標記與XSD的問題。否則,對XSD感興趣的人將無法找到它。接下來,如果您有關於XML Schema的問題,請始終發佈隨附的示例XML文檔。理想情況下,一個XML文檔應該對這個模式有效,另一個應該是無效的。 –