Question: 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

Answer: 
Here is an example of a fragment of an XHTML document:

```
<p>The quick brown fox<br />jumped over the lazy dog</p>

```

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).
Well, I'd say this is a question of definition. If you want to stress that a person has a middle name or not, do it like in your XML snippet with `minOccurs` and `maxOccurs` set to `1` (or different; maybe you want to model persons with more than one middle name?). Otherwise set `minOccurs` to `0` in order to allow to leave it out.

As David shows having an empty element doesn't have to be the same as not having that element at all. It's a question of how you define your semantics.