2012-07-13 70 views
0

我的XML SCHEMA集合發生了什麼問題:x,它引發錯誤。錯誤:在XML SCHEMA集合中多次指定元素或屬性類型

這裏是XML的,我寫了一個XML架構集合的例子:

<ReviewRules xmlns="urn:goldleaf-schema:ReviewRules" version="1.0"> 
    <Name>Never Apply Review Rule</Name> 
    <ReviewBasis>Never</ReviewBasis> 
    <DefaultReviewerComment>Review not required as per rule.</DefaultReviewerComment> 
    <PayLimit AutoReject="True">20000</PayLimit> 
    <UserLimit AutoReject="True">25000</UserLimit> 
    <DailyTotalLimit AutoReject="True">50000</DailyTotalLimit> 
    <TotalLimit AutoReject="True">75000</TotalLimit> 
</ReviewRules> 

XML架構集合:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns ="urn:GAPS-schema:ReviewRules" 
      xmlns:mstns ="urn:GAPS-schema:ReviewRules" 
      targetNamespace="urn:GAPS-schema:ReviewRules" 
      elementFormDefault="qualified"> 
    <xsd:element name="ReviewRules" type="mstns:ReviewRulesType" /> 
    <xsd:complexType name="ReviewRulesType"> 
    <xsd:sequence> 
     <xsd:element name="Name" type="xsd:string" minOccurs="1" maxOccurs="1" /> 
     <xsd:element name="ReviewBasis" type="mstns:ReviewBasisType" minOccurs="1" maxOccurs="1" /> 
     <xsd:element name="DefaultReviewerComment" type="xsd:string" minOccurs="1" maxOccurs="1" /> 
     <xsd:element name="PayLimit" type="xsd:decimal" minOccurs="0" maxOccurs="1" > 
     <xsd:complexType> 
     <xsd:attribute name="AutoReject" type="xsd:boolean" use="required"/> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="UserLimit" type="xsd:decimal" minOccurs="0" maxOccurs="1" > 
     <xsd:complexType> 
     <xsd:attribute name="AutoReject" type="xsd:boolean" use="required"/> 
     </xsd:complexType> 
     </xsd:element> 
     <xsd:element name="DailyTotalLimit" type="xsd:decimal" minOccurs="0" maxOccurs="1" > 
     <xsd:complexType> 
     <xsd:attribute name="AutoReject" type="xsd:boolean" use="required"/> 
     </xsd:complexType> 
     </xsd:element>   
     <xsd:element name="TotalLimit" type="xsd:decimal" minOccurs="0" maxOccurs="1" > 
     <xsd:complexType> 
     <xsd:attribute name="AutoReject" type="xsd:boolean" use="required"/> 
     </xsd:complexType> 
     </xsd:element> 
    </xsd:sequence> 
    <xsd:attribute name="version" type="xsd:string" fixed="1.0" use="required"> 
     <xsd:annotation> 
     <xsd:documentation>Version attribute should be fixed and increase if there is any schema change for review rules.</xsd:documentation> 
     </xsd:annotation> 
    </xsd:attribute> 
    </xsd:complexType> 
    <xsd:simpleType name="ReviewBasisType"> 
    <xsd:restriction base="xsd:token"> 
     <xsd:enumeration value="Never" /> 
     <xsd:enumeration value="Always" /> 
     <xsd:enumeration value="Limits" /> 
    </xsd:restriction> 
    </xsd:simpleType> 
</xsd:schema> 

此XSD無法驗證XML,並給予錯誤:

元素或屬性類型指定多次。位置:'/ :schema [1]/:complexType [1]/:sequence [1]/:element [4]/*:complexType [1]'。 消息6314,級別16,狀態1,3號線

回答

0

您可能會發現Saxon的錯誤消息的更多幫助:

Error at xsd:element on line 11 column 84 of test.xsd: 
    A <complexType> element must not appear as a child of an <xsd:element> with a @type attribute 
Error at xsd:element on line 16 column 85 of test.xsd: 
    A <complexType> element must not appear as a child of an <xsd:element> with a @type attribute 
Error at xsd:element on line 21 column 91 of test.xsd: 
    A <complexType> element must not appear as a child of an <xsd:element> with a @type attribute 
Error at xsd:element on line 26 column 86 of test.xsd: 
    A <complexType> element must not appear as a child of an <xsd:element> with a @type attribute 
Schema processing failed: 4 errors were found while processing the schema 

基本上,你可以指定一個元素要麼類型的類型屬性,或與一個complexType子元素,但你不能有兩個 - 它沒有意義。

+0

好吧我同意,但作爲屬性元素的類型給出了相同的錯誤。試過這也 ' – PawanS 2012-07-13 19:46:56

+1

那是一個不同的錯誤。您不能將xs:attribute作爲xs:element的子項。不要試圖猜測XSD語法 - 你永遠不會猜對。 – 2012-07-14 17:12:10

相關問題