Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xml addiding and deleting elements

 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to use DOM?
 
Neh Agarwal
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know little about DOM, I was trying to use DOM for this, but am stuck, please help!
 
Paul Clapham
Sheriff
Posts: 21152
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the code that you're using for editing and saving.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic