OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] Create XML

[ Lists Home | Date Index | Thread Index ]

[Rick Marshall]

> ok, i need to have something in real time, callable as a C library that
> works like a printf.
> ...
> for our large database applications i want to output Mbytes of xml in a
> stream as i'm processing records. this is a different problem.
> xml_start_document()
> puts out an xml header string "<?xml etc". possibly needs some
> arguments, but can get away without it for now.
> xml_start_tag(tag)
> puts out "<tag", checking for character errors. pushes tag context onto
> an internal stack.
> ... [more API stuff elided]

See, the thing is, you have two ways to go.  One is to do what you are
suggesting.  Only you are reinventing a SAX handler.  Why don't you just get
a SAX handler, and create the Sax events for it as you stream your data into
it?  No need to reinvent it (though your code would probably be lighter
weight, you wouldn't have to write it,and you could use any SAX handler)
SAX 1 would be simpler (I am assuming you do not need namespaces).

The other way to go is to figure out how, at each step, you would
automatically get well-formedness.  Well, maybe that is too much, but go as
far as possible in that direction.  You say you are getting data from a
database, so presumably that will be rows.  Then collect a row from the
file, and call


do_row is supposed to make sure the row is well-formed.  Add its results to
your output.  This way you do not have to worry about missing an end call,
etc., and there are fewer calls to write in the handler.

If you have a simple nested structure, you could do something like


Once again, you guarantee that everything is properly closed without having
to get a lot of details right every time you write a new handler for a new
type of data.  This may get too hard for an arbitrary and changable nested
document, but that is not what you have mentioned.


Tom P


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS