Whoops! I made some mistakes copying the code so please discard the previous message and instead check this one:<br><br> List <Element> wordList;<br> ListIterator listIterator;<br> Element currentElement;<br>
boolean isWanted = false;<br><br> Btn.addActionListener(new ActionListener() {
<br> public void actionPerformed(ActionEvent e) {<br> try {<br> isWanted = true;<span class="q"><br> try {<br> BufferedWriter writer = new BufferedWriter (
<br> new OutputStreamWriter (<br> new FileOutputStream ("words.txt"),<br> "UTF-8"));<br></span><span class="q"> Format format =
Format.getPrettyFormat();<br> format.setEncoding("UTF-8");<br></span><span class="q"> XMLOutputter outputter = new XMLOutputter(format);<br></span>
writer.write
("<word_list>");<span class="q"><br> writer.newLine();<br> writer.write("<title name ='words' />");<br>
writer.newLine
();<br></span> if(isWanted == true){<br> while (listIterator.hasNext()){<span class="q"><br> outputter.output(currentElement, writer);
<br>
writer.newLine();<br> }<br> }<br></span> else {<span class="q"><br> writer.write("</word_list>");
<br>
writer.flush();<br> writer.close();<br> }<br> }<br> catch (IOException io) {}<br></span> advance();<br>
}<br> catch (NullPointerException ne) { }<br> }<br> });<br><br> public void advance() {<br> isWanted= false;<br> //begin, get and print element<br> if(listIterator == null) {
<br> listIterator = wordList.listIterator();<br> if(
listIterator.hasNext()) {<br> currentElement = (Element)listIterator.next();<br> txtWord.setText("<html>"+currentElement<div id="mb_5">.getAttribute("word").getValue());
<br>
}<br> }<br> //reached end, start over<br> else {<br> listIterator = wordList.listIterator();<br> currentElement = (Element)listIterator.next();
<br> }<br> }</div><br>