I have a hierarchy of objects that are transmitted via XML. The hierarchy rules are easy to express in XML Schema by stating which element may contain which child elements. A simplifed example of the XML data would be (the actual object data is contained in attributes and omitted for brevity):
<root>
<channel>
<router>
<message />
<message />
<message />
</router>
<router>
<message />
<message />
</router>
</channel>
<channel></channel>
</root>
Now I'd like to introduce "folders", i. e. nodes that just serve to structure long lists of children for easier use. If I make a generic <folder>
element, it would not impose rules of its own, but inherit them from the next non-folder element up the tree.
It seems to me that I can't express that in XSD, or can I?
I can think of alternatives, like having specific folder elements for each possible rule (ugly), simply ignoring the rules in XSD and enforcing them in code (fine with me) or somehow separating object hierarchy and intermediate nodes in the XML (not quite sure how). I'd appreciate your comments on that, too, if you have any.