[
Lists Home |
Date Index |
Thread Index
]
- From: Paul Miller <stele@fxtech.com>
- To: sml-dev@egroups.com, xml-dev <xml-dev@ic.ac.uk>
- Date: Sat, 01 Jan 2000 12:50:16 -0500
XMLIO is my lightweight library for generating and processing SML/XML
streams in C or C++ applications where application data structures or
configuration settings are stored as XML syntax.
The latest version is completely rewritten in C, with the C++ API
layered over that (but using exceptions, references, and in the XML::
namespace). The XML input processor (XML_Input and XML::Input) is a
hybrid push/pull model where specific element handlers are specified for
each level of a nested object hierarchy. When a desired element is
encounted, a callback handler is called (like with a push model), but it
is up to the handler to pull what it needs (either data or more
subelements). If nothing is requested, the entire element is skipped.
Because element processing is performed on the stack and unused elements
are thrown away immediately, there is no memory overhead during
processing, making it extremely efficient.
Intrinsic data types (including ints, floats, doubles, booleans,
strings, and list enums) corresponding to object member data can
automatically be processed and stored at the correct address in the
object. Custom processors can be easily written to handle custom element
data.
Here is an example on how to process the following XML syntax into some
sample objects:
<Circle>
<Center>(100,100)</Center>
<Radius>50</Radius>
</Circle>
typedef struct Point_
{
int x, y;
} Point;
XML_Error Read_Point(XML_Element *elem, Point *p)
{
XML_Char data[40];
size_t len = sizeof(data) / sizeof(XML_Char);
XML_Error error = XML_ElementReadData(elem, data, &len);
data[len] = 0;
if (sscanf(data, "(%dx%d)", &p->x, &p->y) != 2)
return XML_Error_InvalidValue;
return error;
}
typedef struct Circle_
{
Point center;
int radius;
} Circle;
XML_Error Read_Circle(XML_Element *elem, Circle *circle)
{
const XML_Handler handlers[] = {
XML_ELEMENT_HANDLER_MEMBER("Center", Read_Point, Circle,
center),
XML_INT_HANDLER("Radius", Circle, radius),
XML_HANDLER_END
};
return XML_ElementProcess(elem, handlers, circle);
}
Please see the README at http://www.fxtech.com/xmlio for complete
details.
--
Paul Miller - stele@fxtech.com
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo@ic.ac.uk the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)
|