File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to delete empty tag from XML

 
ram gaurav
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <name /> has no children (since the content of an element == a child element itself). You could just match on that and delete it.
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can run a simple style sheet to filter out the empty element. The below one should work for you.
 
ram gaurav
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 425
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic