XML
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   karthi_forum
Posted On:   Saturday, January 6, 2007 12:28 AM

Hi, This is karthi.i need a java code using dom to insert(dynamically) a new tag to the existing xml file.The new tag is available with me as string . for example let us take Sample.xml file <?xml version="1.0" encoding="utf-8"?> 3453454 98776765 karthi In the above file i need to insert a tag "hello welcome" dynamically between 'message-id' and 'target'tags.This new tag is available for me as a java String object.The file also should contain the new tag.After some times am reading the same xml file with new tag.Pls suggest some solution for this.If anybody having code   More>>


Hi,

This is karthi.i need a java code using dom to insert(dynamically) a new tag to the existing xml file.The new tag is available with me as string .



for example let us take Sample.xml file


			

<?xml version="1.0" encoding="utf-8"?>

3453454
98776765
karthi




In the above file i need to insert a tag "hello welcome" dynamically between 'message-id' and 'target'tags.This new tag is available for me as a java String object.The file also should contain the new tag.After some times am reading the same xml file with new tag.Pls suggest some solution for this.If anybody having code for similar process send it.

thanks in advance..


karthi
java.karthi@gmail.com


Please use html tags to format code blocks.    <<Less

Re: XML

Posted By:   Robert_Lybarger  
Posted On:   Saturday, January 6, 2007 10:12 AM

If the file is as small as you're leading us to believe, then just directly load the file into a java DOM object and do direct manipulation. Sun as a DOM tutorial here that should get you started. They walk through a few scenarios (you want 1 and 4), so you'll have to see the pieces you need and put them together on your own. Specifically, you want a DocumentBuilder to parse a File object, giving you a DOM. Then you want to create a new Element for your tag and nest in/under it a text node for the string value. Then you'll need to insert your Element object into the right spot in the DOM. Then save the DOM back out to a file (which you might need to google around for -- the tutorial doesn't seem to cover this too well).
About | Sitemap | Contact