// Use the FormatterToXML class right not instead of
// the Xerces Serializer classes, because I'm not sure
// yet how to make them handle arbitrary nodes.
FormatterToXML fl = new FormatterToXML(System.out);
TreeWalker tw = new TreeWalker(fl);
int n = nl.getLength();
for(int i = 0; i < n; i++)
{
tw.traverse(nl.item(i));
// We have to do both a flush and a flushWriter here,
// because the FormatterToXML rightly does not flush
// until it get's an endDocument, which usually will
// not happen here.
fl.flush();