I thought that in XML you could have a tag with opening and closing tags, and then if you didn't need the closing tag, you could just use a tag with a slash at the end of it.
<!-- needs text/elements within tag so opening and closing tag are needed -->
<myTag>Text here</myTag>
<!-- doesn't need text/elements so doesn't have closing tag -->
<myTag />
I'm guessing that this is just because that's whatever everyone decided was best and this is now just a XHTML peculiarity, but why? Is there a technical reason for this that I don't know about?
Thanks!
It's because the XHTML DTD says so :)
Only these elements are allowed to be empty:
For example link
is declared as:
<!ELEMENT link EMPTY>
whereas script
and iframe
are declared as:
<!ELEMENT script (#PCDATA)>
and
<!ELEMENT iframe %Flow;>
<!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*">
...
If browsers treated XHTML as XML, you would be right. But they treat it as HTML, where the rules are different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With