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

Jeff Garza jeff.garza at gmail.com
Wed May 23 00:14:03 PDT 2007

I wasn't able to figure out the correct way to use the for statement like
you suggested. I tried using the boolean isWanted = true for initialization,
isWanted = false for termination, and leaving increment blank, but that
didn't work. If you could explain how the proper way to use a for statement
in this situation that would help me a lot.

I also tried to place an if(listIterator.hasNext()) { statement but
depending on where I use it at, it either fails to close the stream and
freezes my computer or it won't do anything at all. The same happens with

Another thing I tried was to have the program access an existing file
instead of creating a new one:

                        SAXBuilder builder = new SAXBuilder();
                        try {
                            String curEl = new String(
                            Document doc = builder.build("file.txt");
                            Element incorrect = new Element("entry");
                            incorrect.setAttribute("word", "curEl");
                            Format format = Format.getPrettyFormat();
                            try {
                            XMLOutputter outputter = new
                            outputter.output(doc, System.out);
                        catch (IOException e2) {
                        } catch (JDOMException e1) {
                            // TODO Auto-generated catch block
                        } catch (IOException e1) {
                            // TODO Auto-generated catch block

This appends the currentElement at the end of the list like I want it to but
it still manages to replace the previous element every time. It also puts an
unwanted "/" at the end which prevents the program from reading it: <entry
word = "word"  />

I wanted try creating a simple text file and modifying that but I need UTF-8
encoding and I only know how to create a simple txt file with FileWriter,
which doesn't allow UTF-8, so I didn't know how to proceed in doing that.

What do you think?

On 5/22/07, Grzegorz Kaczor <grzegorz.kaczor at gmail.com> wrote:
> You can write:
> (...)
> writer.newLine();
> writer.write("<title name ='words' />");
> writer.newLine();
> for (...) {
>    ... wait for user click ...
>    outputter.output...
> }
> writer.write("</word_list>");
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20070523/0c12a5af/attachment.htm

More information about the jdom-interest mailing list