Small XML parser in C

78
8
C

SXML

A Small XML parser written in C.

Inspired by the clean API design used by the JSON parser JSMN, SXML has the same design goal and features for XML parsing. Go read about JSMN’s Philosophy and Features to get an idea of how it differs to other parsers - I’ll wait right here.

Features

Here is a list of features SXML shares with JSMN.

  • compatible with C89
  • no dependencies
  • highly portable
  • about 420 lines of code
  • extremely small code footprint
  • API contains only 2 functions
  • no dynamic memory allocation
  • incremental single-pass parsing

Usage

The header file is heavily commented and should be the first place to look to get started.

Check out the file sxml_test.c for an example of using SXML within a constrained environment with a fixed sized input and output buffer.

Limitations

In order to remain lightweight the parser has the following limitations:

  • Minimal XML syntax check during parsing
  • Input text must be ascii or an ascii extension (latin-1 and utf-8 are examples of ascii extensions)

Do contact me with suggestions if the limitations above are preventing you from using the parser.

Alternatives

List of alternative lightweight XML parsers considered before writing my own.