• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Modifying xml tag value using java

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an xml file with some tags repeating. I need to update a tag value with some value. That particular tag is determined by its sibling tag value.

Can someone tell me using what i can achieve this. Or some example for doing the same.

Regards,
Ren
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ren : Sounds like a job for regular expressions, or "regex" for short. Here are
a couple of good resources. This first is introductory the second more advanced.
Good luck.

http://java.sun.com/docs/books/tutorial/essential/regex/index.html

http://www.regular-expressions.info/tutorial.html

Jim...
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that regex is a suitable solutions for this problem because then you'll lose a lot of the flexibility of xml. Although I don't have any experience with it I would recommend you to look at a java XQuery implementation.
 
Marshal
Posts: 25832
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general regular expressions are useless when working with tree-structured data. If you have a trivial XML document and you're willing to take the risk that the part you are changing isn't going to run into conflicts with the XML escaping rules then a regex might work, but usually the way to do that is to parse the document, change the "tag value", and serialize it out to a new document.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:... but usually the way to do that is to parse the document, change the "tag value", and serialize it out to a new document.


This is what I had in mind. To me the problem seemed to invite string
manipulation. Is the fact that it happens to be XML relevant? I suppose
it could be if XML libraries offer some cool tools to help.

Jim...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic