XSD: Extenstion, substituion, and recursion, Oh My!
David M. Aldridge
(Background and details are first, with my questions at the end.)
Consider the following hierarchy:
Foo (abstract base)
At runtime, any Foo instance may have one-or-more Foo children or Bar
I'm trying to represent the above via XML Schema (I'm just learning, and
have only been at this for a couple of days), and have come up with two
possibilities (root element and other minor details omitted):
I prefer the readability of OPTION 1 (XML), but I prefer the schema of
OPTION 2 (XSD), as it doesn't require any <xs:choice> blocks, which is
easier to maintain and extend in my mind -- simply add a new type
extended from Foo, and you're set. With OPTION 1 (XSD), you add the new
type the same way, but then you have to go add a line to the <xs:choice>
block as well.
Additionally, the XSD will only be worked on internally, most likely by
myself, so I'm not worried about flexible extension of the schema by
others; however, the XML document has a higher chance of being
implemented/modified by another individual.
1) Aside from the oddity of the hierarchy (which cannot easily be
rearchitected), does it look like I'm doing anything "wrong" so far with
the schema definition?
2) Is there a better way to achieve the same result? These types (both
Foo<x> and Bar) will be nested/used in other types, so I cannot take the
3) Which of the two solutions above is preferable? Opinions welcome.