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