SimpleXML

(C) Copyright 2002 By Brian Ecker

SimpleXML is a simple C++ tree based parser of valid XML 1.0 documents. It is licensed under the GNU LGPL and is small enough (439 lines) to include directly in your C/C++ applications when you need a small, fast and simple XML language parser.


TREE BASED

SimpleXML is a tree based parser, so it maps the whole file into memory unlike event based parsers (like Xerces) which take actions as they read through the file. Tree based parsers are useful for smaller XML documents (less than 1M) when you want random access to all parts of the XML document (think tape drives vs. ram).


EASY ACCESS

I tried to mimic Perl's simple hash reference syntax in SimpleXML tree accesses (though SimpleXML doesn't make use of hashes). In perl, when you want to access a variable in a hash reference you use a syntax like:

$var = $root->{child_name}->{value};

In the SimpleXML document tree you can access a variable with syntax like:

var = root->child("child_name")->value();

Because the whole document stays mapped in memory until you call the destructor all variable access functions can return const pointers to the values they contain. Because XML can store any type of data, including mixed types, all values are stored and retrieved as character strings. It is up to the caller to do character to integer or floating point conversion.


OBJECT ORIENTED

SimpleXML is written in sparse C++ (so it shouldn't pollute C programs too much). SimpleXML is self contained and doesn't require any external libraries or introduce any unnecessary dependencies to your applications. You can process an XML file by reading the contents into a string and simply calling:

simplexml *root = new simplexml(xml_char_string);


SIMPLE CODEBASE

It would probably take you only 10 minutes to skim through the SimpleXML source and understand how it works. Or you can glance at the header file (simplexml.h) and memorize the API in about 30 seconds. You're probably thinking, "Hell, I could've written this." And you're right. It's very simple. But the point is that you don't have to. All you have to do is include it in your application and gain the benefits of simple, fast, lightweight XML access.

SimpleXML is ideal for short message based protocols where you want the benefits of a standard common syntax without having to write or include a complicated, heavy parser. It's also great for managing program configuration files or for processing and/or relaying small, simple data feeds.


DOWNLOAD

You can download v1.0 of SimpleXML here: simplexml-1.0.tar.gz