Let’s say you want to allow some particular XML element to occur 0+ times. For example, the <record> element can occur multiple times:
<repository>
<record>Record 1</record>
<record>Record 2</record>
<record>Record 3</record>
</repository>
Are there any compelling reasons to include a parent element as a container for these? For example, the following uses the <recordSet> element to contain the <record> elements:
<repository>
<recordSet>
<record>Record 1</record>
<record>Record 2</record>
<record>Record 3</record>
</recordSet>
</repository>
I tried to find any related questions before posing this, so my apologies if it has been asked already. Thanks in advance for any and all input!
Edit – July 22, 2009:
Thanks to everyone for the excellent feedback! (I would comment / vote people up, but I don’t have enough reputation points quite yet.) I’ll probably go ahead with this route, and I also wanted to thank @16bytes for their advice, including to simply name the parent by using the plural of the reoccurring child elements.
Having a parent element makes it simpler to identify sections of the XML and makes it simpler for handlers to map the child elements to a collection.
If you have a system that forbids the use of attributes (some do, it’s annoying), you also need to use wrapper elements to distinguish properties (such as ids) that belong to particular children.
Other than that it is valid to omit the parent element and can make the file markedly less verbose.
In your first example, a user element could be mingled in with the records, this is valid but it might be hard to spot:
Whereas with a surrounding element you can separate the collection, and have multiple instances of that collection: