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).
Some people would say you should use an empty element if you know that the person has no middle name, and you should omit the element if you don't know whether or not they have a middle name. But this is a rather fine distinction for most applications. Make your own choice. There's actually a third option, which is to use `xsi:nil="true"`, but I've never understood why anyone would want to use that.

Remember of course that when you model personal names as (first, middle, last) then you are force-fitting the data into a structure which doesn't match the real variety of personal names used in the world, even if you're only interested in people who live in the United States.