michaelrsweet/Mini-XML — Issue #4: Add capability to load/save with a generic callback
Author: michaelrsweet
Created: 2012-01-01 08:07:52+00:00
State: open

[Originally posted as STR #98 by michael.watkins]

This enhancement would allow a generalized method to be used to load or save XML data with mini XML.

For example, a callback could be specified to new function entry points such as mxmlLoadStream, mxmlSAXLoadStream, mxmlSaveStream, etc.

The callback would consist of a function prototype defined like this:

typedef int (*mxml_read_stream_cb_t)(void *,void *,unsigned int);
typedef int (*mxml_write_stream_cb_t)(void *,const void *,unsigned int);

For the read, the first argument would be the context passed through the entry point, the second argument would be the buffer used to store the data or the data to be written, and the third argument would be the number of bytes to read/write.

Thus, mxmlLoadStream would look like this:

extern mxml_node_t *mxmlLoadStream
(
mxml_node_t *top,
mxml_read_stream_cb_t read_stream_cb,void *read_stream_context,
mxml_type_t (*cb)(mxml_node_t *)
);

Internally, in mxml-file.c new functions would be needed similar to the file descriptor entry points, where a generalized function is called rather than read/write.

In fact, this generalized method could potentially replace all of the separate getc and putc functions currently used (mxml_fd_getc, mxml_file_getc, etc.).