2015-10-20 34 views
-1

我创建针对输入的XML在我的主要要求是做一个模式或者ParcelNumberWorkArea强制性所以这里是我的输入XMLXSD架构错误无效的含量被发现开始元素,无子元素,预计在这一点上

<?xml version="1.0" encoding="utf-8"?> 
<NOCPlantMapRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <NOCTypeID>0</NOCTypeID> 
    <WorkLocation> 
    <ParcelNumber>4545</ParcelNumber> 
    <Roads> 
     <WorkLocationRoad> 
     <RoadName>chennai road</RoadName> 
     </WorkLocationRoad> 
    </Roads> 
    <WorkArea> 
     <WorkArea> 
     <Coordinates> 
      <WorkLocationCoordinate> 
      <CoordinateX>56</CoordinateX> 
      <CoordinateY>23</CoordinateY> 
      </WorkLocationCoordinate> 
     </Coordinates> 
     <Communities /> 
     </WorkArea> 
    </WorkArea> 
    </WorkLocation> 
</NOCPlantMapRequest> 

和以下是我创建验证XML

<?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="NOCReference" minOccurs="0" type="xsd:string" /> 
     <xsd:element name="NOCTypeID" minOccurs="0" type="xsd:unsignedByte" /> 
     <xsd:element name="NOCTypeName" minOccurs="0" type="xsd:string" /> 
     <xsd:element name="ApplicationName" minOccurs="0" type="xsd:string" /> 
     <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:choice> 
     <xsd:sequence> 
     <xsd:element name="ParcelNumber" type="ParcelNumberType" /> 
     </xsd:sequence> 
     <xsd:sequence> 
     <xsd:element name="WorkArea" type="WorkAreaType" /> 
     </xsd:sequence> 
    </xsd:choice> 
    </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: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> 

架构但像

IAM得到错误

我检查Visual Studio和xml-xsd validation tool

+2

难道你没有[**只是问这个问题**](http://stackoverflow.com/q/33183835/290085)?如果所有来自Abel的人都非常善于帮助解决XSD问题,但无法解决您的问题,您应该重新检查您是如何提出问题的。 stackoverflow.com/help/how-to-ask)。 – kjhughes

回答

3
在你的.xsd

,的locationType只接受ParcelNumber或工作区,道路或社区未在任何地方被发现。

这也是有点不寻常有2 XSD:序列内的xsd:选择,通常你只想做这样的事情:

<xsd:complexType name="LocationType"> 
    <xsd:all> 
    <xsd:element name="ParcelNumber" type="ParcelNumberType" maxOccurs="1"/> 
    <xsd:element name="WorkArea" type="WorkAreaType" maxOccurs="1"/> 
    </xsd:all> 
</xsd:complexType> 

这是一个完整的XSD应该验证XML例如:

<?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="NOCReference" minOccurs="0" type="xsd:string"/> 
       <xsd:element name="NOCTypeID" minOccurs="0" type="xsd:unsignedByte"/> 
       <xsd:element name="NOCTypeName" minOccurs="0" type="xsd:string"/> 
       <xsd:element name="ApplicationName" minOccurs="0" type="xsd:string"/> 
       <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> 
+0

你是冠军,让我在接受答案之前做进一步测试,虽然最初是成功的 – peter

相关问题