aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to delete empty tag from XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to delete empty tag from XML" Watch "How to delete empty tag from XML" New topic
Author

How to delete empty tag from XML

ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
Hi

I am having one XML file with following data.



Now , in above file one NAME tag is empty.So i want that while traversing through XML file , i have to delete that blank record.

Can you please tell me that how to get that.

Thanks
Ram
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The <name /> has no children (since the content of an element == a child element itself). You could just match on that and delete it.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
You can run a simple style sheet to filter out the empty element. The below one should work for you.
ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
Sir , Thanks a lot for your reply.

But i am new to XML so can you please tell me that how to run stylesheet.

Thanks
Ram
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Download Xalan for Java the below URL explains how to run the stylesheet.
http://xml.apache.org/xalan-j/commandline.html
You can use any XSLT parser, all you have to do is consult the doc on how to run them. I haven't used the xsl parser that comes with jdk
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to delete empty tag from XML