Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular expression to remove some tags in xml file

 
Ramki Dirisala
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
g tsuji
Ranch Hand
Posts: 669
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 669
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Look very very carefully at this line


It can't possibly match.
 
Ramki Dirisala
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic