List Info

Thread: Generating streaming XML via tree API




Generating streaming XML via tree API
user name
2006-09-28 14:39:30
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">
<P25_log_data>
  <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.


_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
Generating streaming XML via tree API
user name
2006-09-28 15:34:08
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">
> <P25_log_data>
>   <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

Daniel

-- 
Red Hat Virtualization group http://redhat.com/v
irtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillardredhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ |
Rpmfind RPM search engine  http://rpmfind.net/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
Generating streaming XML via tree API
user name
2006-09-28 16:42:38
> On Thu, Sep 28, 2006 at 09:39:30AM -0500, David Hagood
wrote:

>   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
>
I realize that I may not be able to write the document level
tag this way. I

>   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.
>
And I can certainly understand that - and that really is not
what I am
asking for.

What I want is an API which can accept an xmlNodePtr, and
write it and its
children out. The node shall be balanced, closed, etc.

>   There is a streaming writing API: the xmlWriter

Which, as far as I can see, does not have an API to accept
an xmlNodePtr
and write a balanced tag and all its children out. In fact,
it looks to me
like xmlWriter is really little better than printf'ing the
tags out - but
perhaps I am missing something.

Obviously, within the existing library there is code that
can take a
nodeptr and write it out - perhaps that code is not
exported. Perhaps it
should be.

So, what it boils down to is, is there a routine that will
do this, or am
I stuck writing my own version that will walk the node list
and write it
out?
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
Generating streaming XML via tree API
user name
2006-09-28 21:51:38
On Thu, Sep 28, 2006 at 11:42:38AM -0500, David Hagood
wrote:
> > On Thu, Sep 28, 2006 at 09:39:30AM -0500, David
Hagood wrote:
> 
> >   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
> >
> I realize that I may not be able to write the document
level tag this way. I
> 
> >   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.
> >
> And I can certainly understand that - and that really
is not what I am
> asking for.
> 
> What I want is an API which can accept an xmlNodePtr,
and write it and its
> children out. The node shall be balanced, closed, etc.

  http://xmlsoft.org/html/libxml-xmlsave.html#xmlSaveTree
  create the context using your file descriptor
  Apparently the header heed a bit of love, node is a node
and not a document.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/v
irtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillardredhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ |
Rpmfind RPM search engine  http://rpmfind.net/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xmlgnome.org
http://mai
l.gnome.org/mailman/listinfo/xml
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )