[xml] Generating streaming XML via tree API

I am trying to create a program which logs a stream of data, either to a
file or to a socket, in XML using the tree API to build up the data.

Each "thing" being logged maps to a tag with a known, fixed amount of
data, like this:

<?xml version="1.0"?>
<!DOCTYPE P25_log_data SYSTEM "p25_log.dtd">
  <TSBK timestamp="00000000" phys_channel="1" direction="rx" type="osp"
timeslot="0">80 00 22 33 44 55 66 77 88 99 97 AC</TSBK>
 <TSBK timestamp="00000001" phys_channel="1" direction="rx" type="osp"
timeslot="0">81 00 22 33 44 55 66 77 88 99 F8 E9</TSBK>
 <TSBK timestamp="00000002" phys_channel="1" direction="rx" type="osp"
timeslot="0">82 00 33 44 55 66 77 88 99 11 91 CE</TSBK>

And so on, until the log is closed, whereupon the </P25_log_data> end
element is to be generated and the file closed.

So, what I want to do is:

Open the file descriptor.

Create the xml, DOCTYPE and document elements and flush to the file.

For every TSBK received:
  create an xmlNodePtr node containing the data for the TSBK.
  Write that to the log file
  Destroy the node
Until logging is ended.

Write the closing tags for the document.
Close the file.

(The the reason I am using the tree interface is because there are other,
more complicated elements that I've not shown that get built up in pieces,
and the tree interface is nice for automatically closing tags for me and
managing the sub-elements.)

Now, I can use the  xmlDocFormatDump() call to dump a document IFF the
document is completely built in memory. I do not see a clean, simple way
to force the system to flush an incomplete document to file with
formatting, or to write an xmlNodePtr to file with formatting.

So, am I missing something, or is the library "missing something". It
seems to me that there is an asymmetry between reading, which can stream,
and writing, which does not seem to be able to stream.

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