H.v.M.
H.v.M.

Reputation: 1633

How to tell apart XML single tag from tag pair using DOM in java

I'm using DOM to parse XML, and I want to be able to tell apart the XML files

<a><b/></a>

and

<a><b></b></a>

How do I do this? I know how to retrieve the b tag as a node, but there doesn't seem to be a method I can use for this task in the Node or Element class.

Upvotes: 1

Views: 431

Answers (1)

Jeff Adamson
Jeff Adamson

Reputation: 415

The two forms are defined to be equivalent and therefor indistinguishable to DOM based models.

The relevant part of the spec is the definition and surrounding content at http://www.w3.org/TR/REC-xml/#dt-empty

[Definition: An element with no content is said to be empty.] The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag.

Spec recommends for compatibility but does not require, that contentspec=EMPTY elements e.g.
use the empty-element style tags and others use the paired syntax e.g. http://www.w3.org/TR/REC-xml/#d0e2480

Upvotes: 4

Related Questions