Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD restriction of element with inheritance doesn't work

I'm trying inherit and restrict an element but I'm getting following error (in eclipse validation):

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

The "Description" element should not be part of the "TypeDevice" element. I just can't get it why. This should be possible (according to this tutorial):

Can anyone help me?

Greets,

Bill

<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>
like image 978
Bill Avatar asked Oct 06 '22 00:10

Bill


1 Answers

Type AbstractDevice has two required elements, whereas type TypeDevice has only one. Thus TypeDevice is not a valid instance of its base type AbstractDevice. In order to make it valid, you should add minOccurs="0" to Description element or turn the derivation around and use extension.

like image 84
jasso Avatar answered Oct 13 '22 11:10

jasso