Is there a good tiny XML parser for an embedded C project? [closed]

三世轮回 提交于 2019-11-30 06:00:50
karlphillip

I was able to tweak the compilation flags of the following XML parser libraries for C, and cut down more than 50% of their size on my Ubuntu machine. Mini-XML is the only one close to what you requested:

There's a good discussion here:

C XML library for Embedded Systems

I was searching for one recently and I found SimpleXML (http://simplexml.sourceforge.net/) and the slightly larger sxmlc(http://sourceforge.net/projects/sxmlc/)

I find SimpleXML more interesting because it's simpler, I didn't try it but it looks like it matches what I have in mind, a single file(well .h and .c) library that doesn't support exotic XML features.

The simple XML parser is a tiny parser for a subset of XML (everything except entities and namespaces). It uses a simple "one-handler per tag" interface and is suited for use with devices with limited resources.

You can always roll your own implementation. I did this a few years ago, and just now added some interface documentation to the code at mercurial.intuxication.org/hg/cstuff.

Please note that the parser has never been used in a production environment or even been tested more than rudimentarily; comments are non-existent as well, so have fun grokking the code if you need to modify it ;)

Try yxml — it's really small and fast non–validating parser.

I developed sxmlc ("Simple XML in C") exactly to be like that: as little files as possible. It's only one file, with an optional "search" file you can add if you need XPath-like search through the document.

It handles DOM-style loading (the whole document tree in memory) or SAX-style loading (calling callbacks whenever a node is read with its attributes, or text was read on a node). If memory is a concern you'll be interested in SAX.

Some people were also interested by the fact that it can parse either files or memory buffers (useful when you get XML as a web reply).

It handles Unicode files since version 4 through #define, so if you don't need Unicode, just don't define the SXMLC_UNICODE and there won't be any weight increase in the binary.

I also have to say it keeps comments when writing back XML to disk! I always felt sorry when people spend time explaining configuration syntax in XML files ("put 'true' to enable special compression..."), which are wiped when saved back by the application.

It compiles under Linux and Windows. I had good feedback from people happily embedding it in routers.

As I want to keep it as simple as possible, I will probably not add new functions but rather improve the existing ones (and correct bugs, of course! :)). I am not very active in its development, unless bugs are reported.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!