[jdom-interest] Writing a list of currentElements using
XMLOutputter
Jeff Garza
jeff.garza at gmail.com
Wed May 23 12:59:45 PDT 2007
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();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20070523/b265dc35/attachment.htm
More information about the jdom-interest
mailing list