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

Jeff Garza jeff.garza at gmail.com
Wed May 23 12:54:13 PDT 2007


  Here is my latest attempt:

    List <Element> wordList;
    ListIterator listIterator;
    Element currentElement;
    boolean isWanted = false;

        Btn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    isWrong = true;
                    if(isPrevious == false){
                        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();
                            if(isWrong == true){
                                while (listIterator.hasNext()){
                                    outputter.output(currentElement,
writer);
                                    writer.newLine();
                                }
                            }
                            else {
                            writer.write("</word_list>");
                            writer.flush();
                            writer.close();
                            }
                        }
                        catch (IOException io) {}
                  advance();
         }

    public void advance() {
        isWanted= false;
            //begin, get and print element
            if(listIterator == null) {
                listIterator = wordList.listIterator();
                if(listIterator.hasNext()) {
                    currentElement = (Element)listIterator.next();
                    txtWord.setText
("<html>"+currentElement.getAttribute("word").getValue());
                }
            }
                //reached end, start over
                else {
                    listIterator = wordList.listIterator();
                    currentElement = (Element)listIterator.next();
                }
            }

This creates the words.txt file like it should but it locks the Btn and
won't close the stream so I end up with a neverending document.

This is killing me.... but I don't want to give up because I've spent way
too much time trying to figure it out!

On 5/23/07, Grzegorz Kaczor <grzegorz.kaczor at gmail.com> wrote:
>
> please attach the whole loop code that sets currentElement too. I
> think that the code you posted is too little to say something about
> the reason of the problem.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20070523/fc428b66/attachment.htm


More information about the jdom-interest mailing list