I’m not this familiar with XML so maybe you’re able to help me 🙂
Let’s say we have a very simple XML document like this one:
<person>
<firstname>John</firstname>
<middlename/>
<familyname>Doe</familyname>
</person>
So, apparently John Doe does not have a middle name. In an xsd file this element is defined as optional with minOccurs=0.
Are there any rules, standards, best practices or whatsoever that define how to handle this empty element? If minOccurs=0 is defined for an element, shall it be removed? Empty elements have, in my opinion, no use except if attributes are used along with that element.
Thanks,
Robert
Here is an example of a fragment of an XHTML document:
There is an empty element with no attributes, but removing it will change the structure of the document.
You can’t remove empty elements as a generic process. You have to make the decision on a case by case basis. In your example it seems reasonable to remove it (actually, it seems somewhat unreasonable to have it in the first place as it seems to be saying that there is a middle name, but it has no data in it).