Re: Writing a list of currentElements using XMLOutputter

"Jeff Garza" <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
Whoops! I made some mistakes copying the code so please discard the previous
message and instead check this one:

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

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

    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();
                }
            }

_______________________________________________
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.