Are elements allowed to nest within themselves?

Chris von See (cvonsee@onramp.net)
Wed, 09 Sep 1998 14:48:33 -0500


The XML 1.0 spec is unclear (unless I missed the reference) on whether or
not an element can nest within itself. For example, let's say I define a
DTD with:

<!ELEMENT foo ( foo*, bar* )>
<!ATTLIST foo answer CDATA #IMPLIED>

<!ELEMENT bar (#PCDATA)>

and a document with:

<!-- top-level "foo" element -->
<foo>
<!-- first nested "foo" element -->
<foo answer="yes">
<bar>this one</bar>
<bar>that one</bar>
</foo>
<!-- second nested "foo" element -->
<foo answer="no">
<bar>the other one</bar>
</foo>
<!-- third nested "foo" element (empty) -->
<foo/>
</foo>

Is this legal?

Chris