tags:

views:

34

answers:

2

I am designing an XML schema to hold the output of my program. However, I am hesitating concerning a design decision, and I would like the input of more experienced programmers.

If I have a complex element

<list>
<elmt>1</elmt>
<elmt>2</elmt>
</list>

However, the nested elements in <list> are optional. My question is how should the file look like when no <elmt> exist?

Option 1:
<list/> or <list></list>

Option 2: <list size="0" />

Option 3: Remove the element <list> altogether.

I know that these 3 options may not have any difference, but does someone have any preference for some reason (I care more about faster reading of the XML file and easier programming than size)?

+1  A: 

Definitely not option 2. I would prefer option 1 as programmer (the less flexible the schema is, the easier is parsing it) and option 3 as human being writing or reading the XML (fewer characters to type, less clutter). It depends on who is more important for you.

Tim Jansen
A: 

Depends if there are any attributes on <list>

If not <list> would not be present if there where no <elmt> members

If there are attributes on <list> e.g. <list thing="value"> then <list> would exist even though there where no <elmt> members

TFD