473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

substitutiongroups and inheritance

I'm having trouble translating my object inheritance models to xmlschema
and have illustrated this in the attached example xsd and xml.

In my example I have a canvas for drawing a new painting and the xsd
contains the instructions for drawing this painting. According to
instructor Bob, a painting constists of two basic parts: background and
foreground. An object is either a background or foreground object.
In the final stage, Bob removes objects that turned out ugly. This can
be any type of object.

The schema defines an abstract type "shape" which "fgshape" and gbshape"
inherit from. It uses substitutiongroups with head "shape".
<drawBackground> only accepts background shapes, <drawForeground> only
accepts foreground shapes, while <eraseShapes> accepts everything.

The problem is that the painting as defined in painting.xml is not valid
according to the schema, because <eraseShapes> expects an element of
type <shape>, rather than <cloud> or its substitutiongroup <fgshape>.
The error xmlbeans gives is:
Validation error at line: 12: Expected element
'shape@http://prutser.cx/schemas/painting' instead of
'cloud@http://prutser.cx/schemas/painting' here in element
eraseShapes@http://prutser.cx/schemas/painting

In an OO programming language this is not a problem. Cloud extends
fgshape, while fgshape extends shape, so you'll have no problem passing
a cloud instance to eraseShapes.

How does one tackle this problem? Am I using substitutionGroups
incorrectly? I do want to be able to use the names of the concrete
elements, rather than <shape type="cloud" color="white"
cloudtype="cumulunimbus"/> if that's possible.

cheers,
Erik van Zijst
Mar 10 '06 #1
1 1117
Nevermind, I think I solved it.

I missed the substitution group relation between the abstract types and
the head. I just added substitutionGroup="shape" to fgshape and bgshape
and now it works.
I guess I just missed it as I was relying too much on inheritance. I
probably figured the hierarchy alone was enough for <eraseShape> to
accept <cloud>, as you would expect in OOP, so I didn't bother to apply
them to the abstract types.

Thanks for being my rubber duck ;)
Erik
Erik van Zijst wrote:
I'm having trouble translating my object inheritance models to xmlschema
and have illustrated this in the attached example xsd and xml.

In my example I have a canvas for drawing a new painting and the xsd
contains the instructions for drawing this painting. According to
instructor Bob, a painting constists of two basic parts: background and
foreground. An object is either a background or foreground object.
In the final stage, Bob removes objects that turned out ugly. This can
be any type of object.

The schema defines an abstract type "shape" which "fgshape" and gbshape"
inherit from. It uses substitutiongroups with head "shape".
<drawBackground> only accepts background shapes, <drawForeground> only
accepts foreground shapes, while <eraseShapes> accepts everything.

The problem is that the painting as defined in painting.xml is not valid
according to the schema, because <eraseShapes> expects an element of
type <shape>, rather than <cloud> or its substitutiongroup <fgshape>.
The error xmlbeans gives is:
Validation error at line: 12: Expected element
'shape@http://prutser.cx/schemas/painting' instead of
'cloud@http://prutser.cx/schemas/painting' here in element
eraseShapes@http://prutser.cx/schemas/painting

In an OO programming language this is not a problem. Cloud extends
fgshape, while fgshape extends shape, so you'll have no problem passing
a cloud instance to eraseShapes.

How does one tackle this problem? Am I using substitutionGroups
incorrectly? I do want to be able to use the names of the concrete
elements, rather than <shape type="cloud" color="white"
cloudtype="cumulunimbus"/> if that's possible.

cheers,
Erik van Zijst
------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<painting xmlns="http://prutser.cx/schemas/painting"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<drawBackground>
<cloud color="white" cloudtype="cumulunimbus"/>
</drawBackground>
<drawForeground>
<tree color="green" height="22"/>
</drawForeground>
<eraseShapes>
<cloud color="white" cloudtype="cumulunimbus"/>
</eraseShapes>
</painting>
------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://prutser.cx/schemas/painting"
xmlns="http://prutser.cx/schemas/painting"
xmlns:tns="http://prutser.cx/schemas/painting"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xs:element name="painting">
<xs:complexType>
<xs:sequence>
<xs:element ref="drawBackground"/>
<xs:element ref="drawForeground"/>
<xs:element ref="eraseShapes"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="drawBackground">
<xs:complexType>
<xs:sequence>
<xs:element ref="bgshape" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="drawForeground">
<xs:complexType>
<xs:sequence>
<xs:element ref="fgshape" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="eraseShapes">
<xs:complexType>
<xs:sequence>
<xs:element ref="shape" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="shape" type="shape-type" abstract="true"/>
<xs:complexType name="shape-type" abstract="true">
<xs:attribute name="color" type="xs:string" use="required"/>
<xs:attribute name="preferredBrush" type="xs:string" use="optional"/>
</xs:complexType>

<xs:element name="bgshape" type="bgshape-type" abstract="true"/>
<xs:complexType name="bgshape-type" abstract="true">
<xs:complexContent>
<xs:extension base="shape-type"/>
</xs:complexContent>
</xs:complexType>

<xs:element name="cloud" type="cloud-type" substitutionGroup="bgshape"/>
<xs:complexType name="cloud-type">
<xs:complexContent>
<xs:extension base="bgshape-type">
<xs:attribute name="cloudtype" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="fgshape" type="fgshape-type" abstract="true"/>
<xs:complexType name="fgshape-type" abstract="true">
<xs:complexContent>
<xs:extension base="shape-type"/>
</xs:complexContent>
</xs:complexType>

<xs:element name="tree" type="tree-type" substitutionGroup="fgshape"/>
<xs:complexType name="tree-type">
<xs:complexContent>
<xs:extension base="fgshape-type">
<xs:attribute name="height" type="xs:int" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

</xs:schema>

Mar 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ricky Romaya | last post by:
Hi, Are there any ways to get multiple inheritace in PHP4? For example, I have 3 parent class, class A, B, and C. I want class X to inherit all those 3 classes. Consider merging those 3 classes...
0
by: John Hunter | last post by:
I am using pycxx 5.2.2 to implement some extension code and have a problem relating to inheritance. I have a pure virtual base class and two concrete derived classes. In the code below, everthing...
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
6
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.