0

I'm using JDOM to parse an xml document that could be like this:

<person>
  <name id="blah"> xyz </name>
  <friends />
</person>

I'm trying to find out what the correct way to detect an empty tag such as <friends /> or <friends></friends>

would be.

Cœur
  • 37,241
  • 25
  • 195
  • 267
hipsandy
  • 982
  • 8
  • 7

1 Answers1

1

Get the Element for the <friends> tag and for an empty element the getChildren() method should return an empty list.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • Thanks Jim. But when there is a non-empty element without any children such as below, the test fails. ` xyz list of friends ` – hipsandy Jun 26 '15 at 18:22
  • Where is the "empty element" in that? I don't understand. Do you mean to say the `` tag is empty because it contains only text and not other tags? In that case you must examine the contained element(s) to distinguish between text and other tags. – Jim Garrison Jun 26 '15 at 18:23
  • Please put all this clarification into the original question, not in comments. When the question is clear I'll update my answer. – Jim Garrison Jun 26 '15 at 18:26
  • Ykw, you're right. The example in my comment doesn't qualify as an empty element. – hipsandy Jun 26 '15 at 18:29