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 How to avoid overwrite in the XML while marshal mentioned inside of for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to avoid overwrite in the XML while marshal mentioned inside of for loop" Watch "How to avoid overwrite in the XML while marshal mentioned inside of for loop" New topic
Author

How to avoid overwrite in the XML while marshal mentioned inside of for loop

Srinivasan Chinnaraj
Greenhorn

Joined: Mar 18, 2013
Posts: 6

I am trying to marshal java object into XML. i want to marshal java object into XML while it inside the for loop.

for(i=0;i<=2;i++){

........................
...........................
...........................

jaxbMarshaller.marshal(details, xmlFile);

}

for the above code it's overwriting in the XML file after completion of each loop . but i want to write in new line after completion of each loop. Please let me know , how to do?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Please do take out time to CarefullyChooseOneForum. I have moved your topic to a more appropriate forum. The original forum you had posted is for questions related to the Ranch


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
You code does exactly what it says, repeatedly writes to the same file.

Just marshal the whole collection, then you will get the correct XML document root and the members.

Bill


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to avoid overwrite in the XML while marshal mentioned inside of for loop
 
Similar Threads
readObject from Stream till EOF
how to get XML from javaobject using JAXB
Castor trouble
how to get xml from java object using JAXB
Java JDBC jtable only displaying one record