Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

Re: [jdom-interest] Writing a list of currentElements using
 XMLOutputter

Grzegorz Kaczor

2007-05-22

Replies:

Hi Jeff,
but in the code you create a new file for each currentElement so it isbehaving correctly.
You can write:(...)writer.newLine();writer.write("<title name ='words' />");writer.newLine();for (...) {  ... wait for user click ...  outputter.output...}writer.write("</word_list>");
Perhaps you will have to flush the writer too if you want to see theresults immediately after each iteration.
However if you have to have a correct XML file after each loopiteration I am afraid you will have to parse, modify and output theXML file again after each click. XML is not designed to support"appending" to the end. In such a situation I would suggest to createa simple text file, append to it and convert it to an XML documentafterwards.
Grzegorz
On 22/05/07, Jeff Garza <jeff.garza@(protected)!
ntword3" >>     <def>currentdef3</def>>  </entry>> </word_list>>> Here is my code:>>                try {>                  BufferedWriter writer = new> BufferedWriter (>                        new OutputStreamWriter (>                           new FileOutputStream> (" words.txt"),>       "UTF-8"));>                  Format format => Format.getPrettyFormat();>                  format.setEncoding("UTF-8");>                  XMLOutputter outputter = new> XMLOutputter(format);>                  writer.write("<word_list>");>                  writer.newLine();>                  writer.write("<title name ='words' />");>                   writer.newLine();>                  outputter.output(currentElement, writer);>     writer.newLine();>                  writer.write("</word_list>");>                   writer.flush();>              !
    writer.close();>               }>              
catch (IOException io) {}>> I'm not sure what to do and I'd appreciate your help. Thanks!> _______________________________________________> To control your jdom-interest membership:> http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)>

-- "Cho? tyle wiemy w?asnym do?wiadczeniem:W nas jest Raj, Piek?o - i do obu - szlaki."J.K.
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.