473,811 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

substitutiongro ups 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 substitutiongro ups 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 substitutiongro up <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@htt p://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 substitutionGro ups
incorrectly? I do want to be able to use the names of the concrete
elements, rather than <shape type="cloud" color="white"
cloudtype="cumu lunimbus"/> if that's possible.

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

I missed the substitution group relation between the abstract types and
the head. I just added substitutionGro up="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 substitutiongro ups 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 substitutiongro up <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@htt p://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 substitutionGro ups
incorrectly? I do want to be able to use the names of the concrete
elements, rather than <shape type="cloud" color="white"
cloudtype="cumu lunimbus"/> 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="cumu lunimbus"/>
</drawBackground>
<drawForeground >
<tree color="green" height="22"/>
</drawForeground>
<eraseShapes>
<cloud color="white" cloudtype="cumu lunimbus"/>
</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="drawBackgr ound"/>
<xs:element ref="drawForegr ound"/>
<xs:element ref="eraseShape s"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="drawBackg round">
<xs:complexType >
<xs:sequence>
<xs:element ref="bgshape" minOccurs="1" maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="drawForeg round">
<xs:complexType >
<xs:sequence>
<xs:element ref="fgshape" minOccurs="1" maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="eraseShap es">
<xs:complexType >
<xs:sequence>
<xs:element ref="shape" minOccurs="1" maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

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

<xs:element name="bgshape" type="bgshape-type" abstract="true"/>
<xs:complexTy pe name="bgshape-type" abstract="true" >
<xs:complexCont ent>
<xs:extension base="shape-type"/>
</xs:complexConte nt>
</xs:complexType>

<xs:element name="cloud" type="cloud-type" substitutionGro up="bgshape"/>
<xs:complexTy pe name="cloud-type">
<xs:complexCont ent>
<xs:extension base="bgshape-type">
<xs:attribute name="cloudtype " type="xs:string " use="required"/>
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:element name="fgshape" type="fgshape-type" abstract="true"/>
<xs:complexTy pe name="fgshape-type" abstract="true" >
<xs:complexCont ent>
<xs:extension base="shape-type"/>
</xs:complexConte nt>
</xs:complexType>

<xs:element name="tree" type="tree-type" substitutionGro up="fgshape"/>
<xs:complexTy pe name="tree-type">
<xs:complexCont ent>
<xs:extension base="fgshape-type">
<xs:attribute name="height" type="xs:int" use="optional"/>
</xs:extension>
</xs:complexConte nt>
</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
3248
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 is out of the question, as there are class Y which only inherits from class A, etc. TIA
0
1465
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 works fine in that the derived classes can use the base method get, but if I try and add a method only available to Derived2, eg, get2, I get a compiler error on the call to add_varargs_method("get2",&Derived2::get2, "get2()\n"); in...
2
4383
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 files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
2
4340
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
2903
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 there shouldn't have been a "virtual" keyword for this purpose, but instead, a "nonvirtual" keyword! In teaching inheritance, you see the common example: class Vehicle {}
5
2185
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 multiple inheritance still be avoided? If yes, why multiple inheritance is introducted into C++?
22
23391
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 examples?
60
4952
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 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
6
3832
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 me somewhat as I have always thought you get code reuse "for free" with inheritance. Am I missing something?. Will someone care to explain ??
0
9727
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.