Re: [xml] Generating streaming XML via tree API

On Thu, Sep 28, 2006 at 09:39:30AM -0500, David Hagood wrote:
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.

  Sorry there is no code in libxml2 for that. Basically any API here which 
will write the open tag will also write the closing tag, ... unless you
use the xmlWriter

(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.)

  So you can't use the XML writer, sorry ...

So, am I missing something, or is the library "missing something". It

  The library has no API to save non balanced XML Fragment, this is basically
a feature to avoid some of the horrors you can see around.

seems to me that there is an asymmetry between reading, which can stream,
and writing, which does not seem to be able to stream.

  There is a streaming writing API: the xmlWriter


Red Hat Virtualization group
Daniel Veillard      | virtualization library
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

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