This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes xml addiding and deleting elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xml addiding and deleting elements" Watch "xml addiding and deleting elements" New topic
Author

xml addiding and deleting elements

Neh Agarwal
Greenhorn

Joined: Feb 27, 2009
Posts: 24
hello,

I have a xml file of the format:


For each product I have to delete the element define with attribute name as LogRootPath, LogGroupPath and LogPath, and it has to be replaced by some other element like, <define name="Path1" value="/root/log">, etc.

Can you please help me do that.
Thanks,
Neha


Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Do you know how to use DOM?


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Neh Agarwal
Greenhorn

Joined: Feb 27, 2009
Posts: 24
I know little about DOM, I was trying to use DOM for this, but am stuck, please help!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I would use XSLT for that. Start with the identity transformation (which copies the whole document unchanged) and add some templates to replace the elements you want to replace.
Neh Agarwal
Greenhorn

Joined: Feb 27, 2009
Posts: 24
It is sort of a requirement for me to use java to do it, and I have reached a place where I am able to change the values and delete the unwanted tag, but it is not saving it back to the xml file. Please help me how to save the xml file.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Post the code that you're using for editing and saving.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml addiding and deleting elements