Reputation: 23
I have a little program using STAX which copy the content of a XML file to another. By the way, I discovered an enigmatic problem with XMLStreamWriter.
When I try to write many elements, the writing works. But when I try to write few elements, it doesn't works (the file is empty).
For example, this code works (3000 elements):
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream("toto.xml"));
writer.writeStartDocument();
for(int i = 0; i < 3000; ++i) {
writer.writeStartElement("toto");
writer.writeEndElement();
}
writer.writeEndDocument();
And this code doesn't work (50 elements):
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream("toto.xml"));
writer.writeStartDocument();
for(int i = 0; i < 50; ++i) {
writer.writeStartElement("toto");
writer.writeEndElement();
}
writer.writeEndDocument();
Have you any idea ?
Upvotes: 1
Views: 725
Reputation: 526
I encountered this too today, but writer.flush()
didn't work, only writer.close()
o_o
Upvotes: 1