When designing an XML structure I sometimes find myself wanting to use similar patterns across multiple element types that appear in the same instance document.
For example, the Head-Body pattern can often be useful if you want to keep data and meta data (data about the data) separate, and sometimes it makes sense for multiple types of element in a document to use that pattern (albeit with different structures).
When you're using the same pattern in multiple element types, does it make sense to:
A) Keep the element names the same? So you might have multiple different types of element called "Head", each having a different structure... (Your "DataSnapshot" element might have a "Head" element within it, and your "CompiledDataSet" element might have a "Head" element within it too, both "Head" elements having different structures.)
B) Or should your element names match the types that are defined in your schema? So, the head element in your "DataSnapshot" element might be named "DataSnapshotHead" instead of just "Head", and your "CompiledDataSet" element might have a head element called "CompiledDataSetHead".
A has the advantage of making the pattern obvious and keeping names short. But I'm guessing it could be confusing for people when elements have the same name but different structures. I think it might make some sorts of XPath queries more complicated too (not sure about that - I've not used XPath much).
B would typically require longer element names, and would make it less clear that the same pattern was being used. But at least the element names would make it clear what type they had.
Below is an example of approach A:
<DataSnapshot>
<Head>
<!-- meta-data that's specific to the
DataSnapshot -->
</Head>
<DataSets>
<StandardDataSet setId="abc">
<Head>
<!-- meta-data that's specific to the
StandardDataSet -->
</Head>
<Values>
<!-- List of values, specific to the
StandardDataSet in their structure -->
</Values>
</StandardDataSet>
<CompiledDataSet setId="xyz">
<Head>
<!-- meta-data that's specific to the
CompiledDataSet. Different structure
to the Head of the StandardDataSet. -->
</Head>
<Values>
<!-- List of values, specific to the
CompiledDataSet in structure.
i.e. different to those of the
StandardDataSet -->
</Values>
</CompiledDataSet>
<!-- Any number of DataSets of different types could
go here -->
</DataSets>
</DataSnapshot>
Note that the example above has multiple elements called "Head" and "Values" that are of different types.
If using approach B, then the example above would have element names like: DataSnapshotHead, StandardDataSetHead, StandardDataSetValues, CompiledDataSetHead, CompiledDataSetValues. The XML would be more bulky, but would it be clearer or easier to parse?
I'm designing a public XML API which is why I'm obsessing over details like this. I want this API to be as intuitive and easy to parse as possible. I've hunted for best practices relating to this, but my Google skills don't seem to be up to it - I've just been finding lots of advice about reusing types in an XML Schema, but nothing about reusing element names. So I'm hoping some of you folks that have worked with a lot more XML than me might have some sage advice about which approach is better?