在扩展复杂类型中改变对简单类型的限制

时间:2010-05-02 07:36:20

标签: xml xsd

我正在尝试创建一个包含2种地址类型的模式。第一个AdressType要求元素Line 1的值至少为10个字符。第二种类型OtherAdressType使用相同的元素从中派生,但不需要Line 1的值。

我尝试了不同的方法但总是出现架构错误,这个错误是:

Invalid particle derivation by restriction - 'Derived element '{namespace}:Line1' is not a valid restriction of base element '{namespace}:Line1' according to Elt:Elt -- NameAndTypeOK.'.

如果我将xs:string类型添加到OtherAdressType:Line1,那么我会收到其他错误。

   <xs:complexType name="AdressType">
    <xs:sequence>
      <xs:element name="Line1" minOccurs="1" maxOccurs="1">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:minLength value="10" />
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
      <xs:element name="Line2" type="xs:string" minOccurs="1" maxOccurs="1"  />
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="OtherAdressType">
    <xs:complexContent>
      <xs:restriction base="AdressType">
        <xs:sequence>
          <xs:element name="Line1" nillable="true">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:minLength value="0" />
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
          <xs:element name="Line2" type="xs:string" minOccurs="1" maxOccurs="1"  />
        </xs:sequence>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>

1 个答案:

答案 0 :(得分:1)

我没有给你一个完整的答案,我很害怕,因为我没有时间详细研究这个问题,但是,你的衍生类型似乎不是一个有效的限制:minLength为0的字符串对minLength为10的字符串的限制:minLength为0的字符串多于10的字符串。

相关问题