File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Add elements to already created XML 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 "Add elements to already created XML" Watch "Add elements to already created XML" New topic
Author

Add elements to already created XML

ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
Hi

I am new to XML.

Right now i am able to read or parse XML with help of my java code.
I have my XML file as follows:



Now i want to update this xml with help of my java code, like with help of my java code i can add more <text></text> element into xml.

Thanks
Gaurav
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
For reading/parsing the xml, you probably used an implementation of SAX.

SAX cant update the xml that you have loaded into memory using java.

You can use DOM to both read/parse xml, update it, then write it out to an output destination like a file.
ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
Thanks for your reply.

Sir can you please give me some small working example that how to add data to XML at runtime.

Thanks
Gaurav
aschwin versteegden
Greenhorn

Joined: Jan 23, 2007
Posts: 3
DO You maybe have an example of the usage of DOM parsing mechanism
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
An example of how to read an XML file and create a DOM Document from it can be found here.

Here is an example of how to add elements to a DOM Document.

And finally, here is an example of how to write a DOM Document to a file.

Putting these pieces together you shoudl be able to read an XML file into a DOM Document, modify it, and then write it back to a file.


Ping & DNS - updated with new look and Ping home screen widget
ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
Thanks a lot all.

My problem is solved with all your helps.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Add elements to already created XML
 
Similar Threads
Namespace declaration using DOM
DOM XML Parsing - Newbie
RootElement is null
How to save the content withen a table into a XML file?
Change XML element using Java