[xml] export DOM tree with SAX interface



Hi Daniel, hi libxml people,

I need a special feature that I believe is not present in libxml right
now. Searching in the list archive, I found the following post under the
subject "[xml] libxml2/sax/write-back" (2002/02/06) :

On Wed, Feb 06, 2002 at 04:46:34PM +0100, thomas porschberg osp-dd de wrote:
I used the sax interface from libxml2 to read a large XML-file into
a specific internal structur for processing.
Now I have the task to write back the data into another XML-file.
What is the typical way to do this work?
I looked at xmlIO.h, but I've got the feeling that this is too much
overhead for such a simple work.

  All the saving routines in libxml2 are currently DOM tree based.

But I won't use printf for writing the XML structure back.
Is there any good example in the air?

  Well, no there isn't any "inverted SAX" which would reserialize
a stream of event, it's somewhere deep in the TODO list. It's relatively
simple but I didn't had the time to do this.

Daniel

I guess you were refering to the following entry of the TODO file :

# - jamesh suggestion: SAX like functions to save a document ie. call a
#   function to open a new element with given attributes, write character
#   data, close last element, etc

I need something similar. Then, as I understand libxml, there are two
ways to achieve this :

A. xmlDocDumpMemory() + xmlSAXUserParseMemory()

B. traverse the tree with functions similar to
xmlDocContentDumpOutput(), xmlNodeDumpOutput() and
xmlNodeListDumpOutput() but instead of writing to a xmlOutputBuffer,
these would call user-supplied callbacks (from a xmlSAXHandler)

Right ?

Obviously A is not efficient. Worse : it's not The Right Thing (tm).  :)
Regarding the implementation of B, I may have some questions, but I'd
like to have your opinion first.

Is there a better approach ? I haven't done any serious work with
libxml, am I missing some really important aspects of its achitecture ?

Thanks,
Fernand



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