Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Empty tags in Java DOM API

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there any method in Java DOM API to handle empty tags? E.g. consider the following XML file.
<?xml version="1.0"?>
<MESSAGE>
<RATES>
</RATES>
</MESSAGE>
here the output, using Java and DOM, is
parent tag is MESSAGE
root is MESSAGE
root is RATES
Value in root is null
Now, consider the following XML file:
<?xml version="1.0"?>
<MESSAGE>
<RATES></RATES>
</MESSAGE>
here the output, using Java and DOM, is
parent tag is MESSAGE
root is MESSAGE
root is RATES.
So, how do we know that there is an empty tag in the XML file?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't empty, there is a Text element in there - of course, this element has nothing but a crlf, but in strict DOM it counts as an element. As I recall, you can get rid of the Text elements by calling the normalize() method on the <MESSAGE> node. This method is part of the org.w3c.dom.Node class.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic