blob: dea2e029740feede647b2a70bb7120ebf50ff55b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
XML parser
==========
Dependencies
------------
- C compiler (C99).
Features
--------
- Relatively small parser.
- Pretty simple API comparable with libexpat.
- Pretty fast.
- Portable
Supports
--------
- Tags in short-form (<img src="lolcat.jpg" title="Meow" />).
- Tag attributes.
- Short attributes without an explicity set value (<input type="checkbox" checked />).
- Comments
- CDATA sections.
- Helper function (xml_entitytostr) to convert XML 1.0 / HTML 2.0 named entities
and numeric entities to UTF-8.
- Reading XML from a fd, string buffer or implement a custom reader:
see: XMLParser.getnext and XMLParser.getnext_data.
Caveats
-------
- Internally fixed-size buffers are used, callbacks like XMLParser.xmldata are
called multiple times for the same tag if the data size is bigger than the
internal buffer size (sizeof(XMLParser.data)). To differentiate between new
calls for data you can use the xml*start and xml*end handlers.
- The XML is not checked for errors so it will continue parsing XML data, this
is by design.
Files used
----------
xml.c and xml.h
Interface / API
---------------
Should be trivial, see xml.c and xml.h and the examples below.
The most minimal implementation to read and parse from fd 0 (stdin) is:
#include "xml.h"
static XMLParser x;
int
main(void)
{
xml_parse_fd(&x, 0); /* xml_parse_string(&x, "<sup />"); */
return 0;
}
Examples
--------
sfeed_opml_import.c or sfeed_web.c or sfeed_xmlenc.c
License
-------
See LICENSE file.
|