File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

xml addiding and deleting elements

Neh Agarwal

Joined: Feb 27, 2009
Posts: 24

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.

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

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

Joined: Oct 14, 2005
Posts: 19973

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

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

Joined: Mar 22, 2005
Posts: 42965
Post the code that you're using for editing and saving.
I agree. Here's the link:
subject: xml addiding and deleting elements
It's not a secret anymore!