问题描述
我有这样一个要求为 ParcelNumber
或坐标像 CoordinateX
或 CoordinateY
强制性的,这两个包含XML不同的层次。因此,如果输入XML包含宗地编号应该返回成功,或者如果它包含坐标,那么它应该返回success.I创建下面的架构,它将返回成功,如果我只发送包裹数量,但如果我派合作坐标它会失败,它要求发送包裹数量是wrong.How实现it.In果壳我有以下问题
I have a requirement like either ParcelNumber
or co-ordinates like CoordinateX
or CoordinateY
mandatory and these two contains different hierarchy in XML . So if the input xml contains parcel number it should return success or if it contains both co-ordinates, then it should return success.I created following schema ,and it will return success if i send only parcel number, but if i send Co-ordinates it will fail ,it is asking to send parcel number which is wrong.How to achieve it.In Nutshell i have following question
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>
修改
如何使用选择任何想法
正确此处
推荐答案
您可以做这样的事情: -
You can do something like this:-
<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>
这篇关于如何使无论是在XML架构强制性的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!