This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Write a Node object to a XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Write a Node object to a XML file" Watch "Write a Node object to a XML file" New topic
Author

Write a Node object to a XML file

Saurabh Joshi
Ranch Hand

Joined: Nov 15, 2007
Posts: 37
Hi,

I am trying hands on DOM API for the first time.

I am in a fix.
My aim is to delete some of the parent tags from one XML file and bring all the child tags to another XML file.
e.g.


I want to remove & and take <c></c> and write to a XML file. <c> has more children under it.

I am trying to implement an approach where I am doing the following -


Now I want to write copyofGetXYZ Node to a XML file.
I am unable to find relevant API to do this.

Kindly suggest the right path.

Thanking you in anticipation.

Regards,
Saurabh.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
You are going to need a separate Document to hold the Node you are moving.

Search for "Harold processing xml with java" to find the free online book which covers all this sort of thing with excellent tutorials.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Saurabh Joshi wrote:Hi,

I am trying hands on DOM API for the first time.


indeed. I would just use XSLT to do that.
Saurabh Joshi
Ranch Hand

Joined: Nov 15, 2007
Posts: 37
Hello William & Paul,

Actually I just figured out the way to do that....


So DOMSource constructor gives us that facility.

Thanks Williams for that book info., it will be a great help further.
Paul, I will surely explore your suggestion and if that's fits the design I will adopt it.

Regards,
Saurabh.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, it does. And you don't even need to make a copy of the node to give to the transformer. Just find the node in your DOM and pass that to the transformer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Write a Node object to a XML file
 
Similar Threads
Java Web Services 2
Doubt with replace all
XPath problem
Write enter/indent with java inside xml file
Put a node into a new xml document