Beginner Question: .write() method for Elements
I just downloaded DOM4J and got it working. I can read
XML files and prettyPrint them, no problem.
But I'm having some trouble getting the .write() method
to work for Elements. I did check a year of archives, but
couldn't find anything.
The Quick start guide says
"A quick and easy way to write a Document (or any
Node) to a Writer is via the write() method.
FileWriter out = new FileWriter("foo.xml") ;
document.write(out);"
OK. But when I try something similar, passing a good pointer
to Document to the following method, using .selectNodes()
to collect <data> elements (there are five of them in the document), and
then using .write() to write them, I get no output.
Could some kind soul tell this beginner what he's doing wrong?
static public void printData(Document document)
throws UnsupportedEncodingException, IOException {
List list = document.selectNodes("//data") ; // collect <data> elements
System.out.println("Length of list is: " + list.size()) ;
System.out.flush() ; // this prints out '5'
OutputStreamWriter osr = new OutputStreamWriter(System.out) ;
Element e ;
Iterator i = list.iterator();
while ( i.hasNext() ) {
e = (Element)i.next() ;
e.write(osr) ; // no output
}
}
}
The above produces no output, whereas the following works perfectly,
printing out the five elements.
static public void printData(Document document)
throws UnsupportedEncodingException, IOException {
List list = document.selectNodes("//data") ;
Iterator i = list.iterator();
while ( i.hasNext() ) {
System.out.println(((Element)i.next()).asXML()) ;
}
}
}
Thanks in advance,
Ken
**********************************************************************
Kenneth R. Beesley [EMAIL PROTECTED]
Xerox Research Centre Europe Tel from France: 04 76 61 50 64
6, chemin de Maupertuis Tel from Abroad: +33 4 76 61 50 64
38240 MEYLAN Fax from France: 04 76 61 50 99
France Fax from Abroad: +33 4 76 61 50 99
XRCE page: http://www.xrce.xerox.com
Personal page: http://www.xrce.xerox.com/people/beesley/beesley.html
**********************************************************************
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user