What are best practices for designing XML schemas? [closed]

One general (but important!) recommendation is never to store multiple logical pieces of data in a single node (be it a text node or an attribute node). Otherwise, you end up needing your own parsing logic on top of the XML parsing logic you normally get for free from your framework.

So in your coordinate example,
<coordinate x="0" y="1" />
and
<coordinate> <x>0</x> <y>1</y> </coordinate>
are both reasonable to me.

But <coordinate> 0,1 </coordinate> isn’t very good, because it’s storing two logical pieces of data (the X-coordinate and the Y-coordinate) in a single XML node—forcing the consumer to parse the data outside of their XML parser. And while splitting a string by a comma is pretty simple, there are still some ambiguities like what happens if there’s an extra comma at the end.

Leave a Comment