Re: Writing a list of currentElements using XMLOutputter

"Jeff Garza" <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
  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 <[email protected]> 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.
>

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.