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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Jim. But when there is a non-empty element without any children such as below, the test fails. <person> <name id="blah"> xyz </name> <friends> list of friends </friends> </person>
Where is the "empty element" in that? I don't understand. Do you mean to say the <friends> 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.
Please put all this clarification into the original question, not in comments. When the question is clear I'll update my answer.
Ykw, you're right. The example in my comment doesn't qualify as an empty element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.