2015-10-20 67 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

相關問題