aspose file tools*
The moose likes XML and Related Technologies and the fly likes Regular expression to remove some tags in xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Regular expression to remove some tags in xml file" Watch "Regular expression to remove some tags in xml file" New topic
Author

Regular expression to remove some tags in xml file

Ramki Dirisala
Greenhorn

Joined: Mar 25, 2011
Posts: 7
Hi,
I have requirement in project, to remove some xml tags from a string.

for ex:

in above code i want to remove content between the <Payload></Payload> tags.

is it possible to do with java reqular expressions. please help me out.

thanks in advance

Ramki.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Hi, this is the Spring forum for questions on the Spring Framework. Your question isn't about Spring.

I am going to move this to the more appropriate forum.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
Such as this.

As in many cases, this kind of approach is adverse to the possibility of nested tags of the same name Payload - that I don't think have to worry in this case?
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 535
    
    3
If you want to inject a bit more generality xml document should entitle to, this would preserve the possible attributes attached to Playload realistic or not, and more importantly, match them as well to begin with.
Ramki Dirisala
Greenhorn

Joined: Mar 25, 2011
Posts: 7
thanks for your quick reply.

but when i run my code with your solution like this



please let me know if i did anything wrong.

Ramki.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781


Look very very carefully at this line


It can't possibly match.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Ramki Dirisala
Greenhorn

Joined: Mar 25, 2011
Posts: 7
i found the problem (i didn't properly closed end tag) now its working fine.

i appreciate your help

thanks,
ramki.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Ramki Dirisala wrote:i found the problem (i didn't properly closed end tag) now its working fine.

i appreciate your help

thanks,
ramki.


Note that the proposed regex and replacement are far more complex than they need to be.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular expression to remove some tags in xml file