Thursday, November 11, 2004

Container elements

If an entity of type A has an association C to many entities of type B the XML could be written thus:


<A>
<B>
<B>
<B>
....
</A>


but there could be multiple associations to entities of type B so maybe it needs to be:


<A>
<C>
<C>
<C>
....
</A>


but now the element name representing entity type B is polluted with the association name. Perhaps it should be like this:


<A>
<C>
<B>
<B>
<B>
....
</C>
</A>


advantages of this are that the association is a first class element, so it can have attributes and the name of the association doesn't effect the name of the contained elements. This also means that role names on associations (in UML) have a precise mapping to an element in the XSD.

I don't think this applies to unary associations though.

Practically it also seems to me that the traversal /A/C/B expresses the intent better that /A/C.