微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xml – 带继承的元素的XSD限制不起作用

我正在尝试继承并限制一个元素,但我得到了以下错误(在 eclipse验证中):

The particle of the type is not a valid restriction of the particle
of the base.

“Description”元素不应该是“TypeDevice”元素的一部分.我无法理解为什么.这应该是可能的(根据这个tutorial):

谁能帮我?

映入眼帘,

法案

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.com" xmlns="http://www.example.com" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <!--  Abstract Base Class  -->
  <xs:complexType name="AbstractDevice" abstract="true">
    <xs:sequence>
      <xs:element name="Name" type="xs:string" />
      <xs:element name="Description" type="xs:string" />
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" />
  </xs:complexType>

  <!--  Inheritance with restriction  -->
  <xs:complexType name="TypeDevice">
    <xs:complexContent>
      <xs:restriction base="AbstractDevice">                                
        <xs:sequence>
          <xs:element name="Name" type="xs:string" />
        </xs:sequence>
        <xs:attribute name="id" type="xs:string" use="required" />
      </xs:restriction>                        
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="TypeRoot">
    <xs:sequence>
      <xs:element name="Device" type="TypeDevice" />
    </xs:sequence>                
  </xs:complexType>
  <xs:element name="Configuration" type="TypeRoot" />
</xs:schema>
类型AbstractDevice有两个必需元素,而TypeDevice类型只有一个.因此,TypeDevice不是其基类型AbstractDevice的有效实例.为了使其有效,您应该将minOccurs =“0”添加到Description元素或转换派生并使用扩展.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。