Re: [xml] Flushing writers doesn't work...?



Daniel Veillard <veillard redhat com>:

On Wed, Feb 09, 2005 at 10:20:45AM +0100, Magnus Lie Hetland wrote:
Hi!

I've been using xmlTextWriters as an abstraction in an internal
event-based system in my app -- but it seems they don't sync properly
when flushed. Maybe I'm expecting too much functionality from
xmlTextWriterFlush()? I've used both writers from

  it calls xmlOutputBufferFlush() if there have been some data added
to the writer, this should really work as expected.

I see. Does this flush the underlying file (in a writer from
xmlNewTextWriterFilename(), for example?

[snip]
  a better explanation of what you're seeing and how it differs from
what you are expecting would help. I still don't see what the problem
might be. You need to be very precise and provide a reproduceable test
case if possible.

Certainly. I've included a simple example below. After running it, the
file flushed.xml is (on my system) empty, while the file destroyed.xml
contains the full document. I get the same behavior when using
tree-building writers.

(BTW: In order to get some progress, I've now written a small tree
builder myself, based on my event system, without using writers, so
there's no real urgency for me anymore -- mainly curiosity.)

-- flushtest.c -------------------------------------------------------
#include <stdlib.h>
#include <libxml/xmlwriter.h>

int main(int argc, char *argv[]) {
  xmlTextWriterPtr writer = xmlNewTextWriterFilename("output.xml", 0);
  xmlTextWriterStartDocument(writer, NULL, "ISO-8859-1", NULL);
  xmlTextWriterStartElement(writer, BAD_CAST "doc");
  xmlTextWriterWriteString(writer, BAD_CAST "Hello, world!");
  xmlTextWriterEndElement(writer);
  xmlTextWriterEndDocument(writer);
  xmlTextWriterFlush(writer);

  system("cp output.xml flushed.xml");

  xmlFreeTextWriter(writer);

  system("cp output.xml destroyed.xml");
}
----------------------------------------------------------------------

-- 
Magnus Lie Hetland       Fallen flower I see / Returning to its branch
http://hetland.org       Ah! a butterfly.           [Arakida Moritake]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]