[英]How to make either of the fields mandatory in XML schema
我有一個要求,例如ParcelNumber
或諸如CoordinateX
或CoordinateY
強制性的CoordinateY
,這兩個要求在XML中包含不同的層次結構。 因此,如果輸入的xml包含包裹編號,則它應該返回成功,或者如果它包含兩個坐標,那么它應該返回成功。我創建了以下模式,如果我僅發送包裹編號,但是如果我發送Co-,它將返回成功。縱坐標它將失敗,它要求發送錯誤的包裹號。如何實現。在果殼中,我有以下問題
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
想法
您可以執行以下操作:
<xs:choice>
<xs:sequence>
<xs:element name="ParcelNumber" />
<xs:element name="CoOrdinates" minOccurs="0" />
</xs:sequence>
<xs:sequence>
<xs:element name="CoOrdinates" />
<xs:element name="ParcelNumber" minOccurs="0" />
</xs:sequence>
</xs:choice>
嘗試這個
<xsd:complexType name="WorkLocationCoordinateType">
<xsd:sequence>
<xsd:element name="CoordinateX" type="xsd:string" minOccurs="1"/>
<xsd:element name="CoordinateY" type="xsd:string" minOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.