tags:

views:

1430

answers:

4

I'm working on a project for an embedded system that's using XML for getting data into and out of the system. I don't want the XML handling to devolve into a bunch of bits that build XML strings using snprintf()/strcat() and friends or parse XML by counting "<" and ">" characters.

I've found several XML libraries, a couple of which might even be small enough, but the closest they come to C is C++, which is not in the cards for this system. I hoping I can find an XML library that meets the following constraints:

  • C source code
  • no dynamic memory allocation
  • cheap. Free is better, but copyleft won't do the trick.

It doesn't have to be a full parser - I just want to be able to pull text out of nested elements and have a reasonably simple way to generate XML that doesn't rely on format strings. Attributes aren't being used (yet), so the library doesn't need to support them even. The XML documents will be pretty small, so something that's DOM-like would be fine, as long as it'll work with client-provided buffers (parsing the raw XML in-place would be nice).

PugXML and TinyXML look to be pretty close, but I'm hoping that someone out there knows about an XML lib tailored just for C-based embedded systems that my googling is missing.

A: 

Xerces-C library would be optimal to use, in this scenario.

Roopesh Majeti
Xerces-C is quite large and written in C++
Indeera
A: 

If it is going to be pretty small XML, why not generate programatically, using sprintf or other stuff and use string extracting functions to parse the same. But as mentioned earlier, if little big, would suggest to use Xerces-c Library, as it is open source

Roopesh Majeti
A: 

You could use an ASN.1 XER encoder; there's a free one at http://lionet.info/asn1c/

Christoffer
+10  A: 

I don't know about dynamic memory allocation, but a standard C XML parser is expat, which is the underlying library for a number of parsers out there.

jvasak
I have always had good experiences with Expat.It written in standard C so should port to any platform fairly easily. Its a stream parser so it shouldnt eat all your memory building a DOM. You need to get used to the 'callback' API but its pretty simple when you get the hang of it.Recommended!
James Anderson
Expat does do some dynamic memory allocation. The code is quite localised though, and you might be able to reimplement. It's a very good XML parser.
anon
If you use the `XML_ParserCreate_MM` to create a parser, it will use the implementations of malloc and free you provide.
Pete Kirkham