On 13 Apr 2005 18:23:59 -0700, "vega" <jo****@gmail.com> wrote:
How do I detect empty tags if I have the DOM document?
For example: <br /> and <br></br>
You can't and you don't need to. In XML these are exactly
equivalent(sic).
http://www.w3.org/TR/2004/REC-xml-20...#sec-starttags
"Empty-element tags MAY be used for any element which has no content,
whether or not it is declared using the keyword EMPTY. For
interoperability, the empty-element tag SHOULD be used, and SHOULD
only be used, for elements which are declared EMPTY."
There may be a useful difference you can find in the element's
definition from DTD or schema - i..e. EMPTY You can access this by
either parsing it, or (more easily) by using a document parser that
understands schema and offers a more direct link to the relevant one.
This is the definition though, not the instance. It won't tell you if
the empty-element form of the tag in your document was used because
it's an EMPTY element, or just a non-empty element that happens to
have no content in this instance.
In general though, the way the document was serialised is not visible
to an XML application and even more importantly there is NO reason why
it needs to be. You just never need it.
If you do think you need it, then the chances are that you're in a
non-XML context, such as XHTML or RSS. Although these are ostensibly
XML protocols, they exist in an environment that's still rooted in the
HTML past. There may be valid reasons for still caring about things
that a purely XML context wouldn't need to.