| Author |
Modifying xml tag value using java
|
renu richard
Ranch Hand
Joined: Oct 06, 2008
Posts: 116
|
|
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
|
Cheers,
Richard
|
 |
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
|
|
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...
|
BEE MBA PMP SCJP-6
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
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.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 12860
|
|
|
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
Joined: Jan 09, 2008
Posts: 525
|
|
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...
|
 |
 |
|
|
subject: Modifying xml tag value using java
|
|
|