0

我的 XML SCHEMA Collection 有什么问题:x,它抛出错误。

以下是我为其编写了 XML SCHEMA COLLECTION 的 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 行

4

1 回答 1

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

基本上,您可以使用 type 属性或 complexType 子元素来指定元素的类型,但您不能同时拥有这两者——这没有意义。

于 2012-07-13T16:28:03.223 回答