The XML you show is well-formed, but there are no "non-empty self-closed elements". If we add some whitespace, we can show the relationships between nodes:
<team>
Chicago Bulls
<playerA/>
23
<playerB/>
43
</team>
So, the team
element has 5 child nodes:
- A text node containing "Chicago Bulls"
- An element called
playerA
with no attributes or content
- A text node containing "23"
- An element called
playerB
with no attributes or content
- A text node containing "43"
No relationship between these nodes is represented, other than their order - in particular, the text "23" is not associated with either of the self-closing elements.
Another way to show this is to remember that <foo/>
is just a different way of writing <foo></foo>
, so we can also write this:
<team>Chicago Bulls<playerA></playerA>23<playerB></playerB>43</team>
In contrast, systematically adding whitespace to your second example would look like this:
<team>
Chicago Bulls
<playerA>
23
</playerA>
<playerB>
43
</playerB>
</team>
In this case, the teams
element has only three direct children:
- A text node containing "Chicago Bulls"
- An element called
playerA
, which contains a text node containing "23"
- An element called
playerB
, which contains a text node containing "43"