> Now, the problem arises when trying to write clean code to process a
> ListType object. You need to perform a lot of runtime type checking like the
> following example:
I think a typical answer to this is the use of the "visitor" design
pattern [1].
The problem I see with your design is that the semantics of modifying
ListOfA is not clear, unless you restrict it to read-only. And also,
yours work only when you can process children separately, and that's not
what you wrote in your first example.
If you just need separate list for each type of items, you can use RELAX
NG and say:
<interleave>
<oneOrMore>
<element name="A"> ... </element>
</oneOrMore>
<oneOrMore>
<element name="B"> ... </element>
</oneOrMore>
<oneOrMore>
<element name="C"> ... </element>
</oneOrMore>
</interleave>
But I'm afraid nothing can be done with XML Schema.
[1]
http://www.google.com/search?q=visitor+design+pattern
regards,
--
Kohsuke KAWAGUCHI 408-276-7063 (x17063)
Sun Microsystems kohsuke.kawaguchi_at_sun.com