aspose file tools*
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
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: 18669
    
    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: 42291
    
  64
Post the code that you're using for editing and saving.


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: xml addiding and deleting elements