-
XML Inheritance
Hi,
I'm having the following problem with XSD authoring.
I want to have a type that includes an element.
Then, I want to inherit from that type, and force the element inside it to be of more specific type.
As I understand, this can be done using restriction derivation, but only if the specific element inside the deriving type is a restriction of the original element.
Is there any idea how to derive from the original type and make the element in the deriving type an extesion of the element in the parent type?
Here is an example, that shows what I want to achieve, but returns error on XMLSpy:
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2011 rel. 3 sp1 (http://www.altova.com) by Asi (Comm-IT) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="Covariance">
<xs:sequence>
<xs:element name="x" type="xs:double"/>
<xs:element name="y" type="xs:double"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ExtendedCovariance">
<xs:complexContent>
<xs:extension base="Covariance">
<xs:sequence>
<xs:element name="z" type="xs:double"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Detection">
<xs:sequence>
<xs:element name="someElement" type="xs:string"/>
<xs:element name="covariance" type="Covariance"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="RestrictedDetection">
<xs:complexContent>
<xs:restriction base="Detection">
<xs:sequence>
<xs:element name="someElement" type="xs:string"/>
<xs:element name="covariance" type="ExtendedCovariance"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
The error message:
Type RestrictedDetection (>def) is not a valid restriction of type Detection (>def).
Does anyone have any idea how can I achive my goal?
-
Unfortunately I am not sure how to accomplish this correctly, however, your error is self explanatory.
"this can be done using restriction derivation, but only if the specific element inside the deriving type is a restriction of the original element"
Your resultant type is not a restriction of the original type, it is an extension of it. If you were to limit or restrict the base type then this would be valid, but adding an element is an extension of the type.
Work around:
<xs:complexType name="ExtendedDetection">
<xs:sequence>
<xs:element name="someElement" type="xs:string"/>
<xs:element name="covariance" type="ExtendedCovariance"/>
</xs:sequence>
</xs:complexType>
Last edited by reedy837; 10-04-2011 at 03:34 AM.
-
I have looked at this in more detail and what you need to use is abstraction instead.
Reference:
http://www.xfront.com/ElementHierarchy.html
Example XSD:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Abstract" type="AbstractType" abstract="true" />
<xs:complexType name="AbstractType" abstract="true">
<xs:sequence>
<xs:element name="x" type="xs:double"/>
<xs:element name="y" type="xs:double"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Extension" type="ExtendedType" substitutionGroup="Abstract" />
<xs:complexType name="ExtendedType">
<xs:complexContent>
<xs:extension base="AbstractType">
<xs:sequence>
<xs:element name="z" type="xs:double"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="AbstractContainer">
<xs:sequence>
<xs:element name="someElement" type="xs:string" />
<xs:element ref="Abstract" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ExtendedAbstractContainer">
<xs:complexContent>
<xs:restriction base="AbstractContainer">
<xs:sequence>
<xs:element name="someElement" type="xs:string" />
<xs:element ref="Extension" />
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Similar Threads
-
By Tim in forum xml.announcements
Replies: 0
Last Post: 10-11-2001, 04:00 PM
-
By xmlstartkabel in forum XML
Replies: 0
Last Post: 10-10-2001, 04:07 AM
-
By Tim Frost in forum xml.announcements
Replies: 0
Last Post: 04-02-2001, 10:53 AM
-
By Extensibility in forum web.announcements
Replies: 0
Last Post: 07-20-2000, 06:20 PM
-
By Sales in forum xml.announcements
Replies: 0
Last Post: 07-20-2000, 06:18 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|