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
|
#include <assert.h>
#include <stdio.h>
#define ASSERT assert
#define IMXML_SIMD_DEFAULT SSE2
#define IMXML_IMPLEMENTATION
#include "imxml.h"
int main (void) {
ImxmlString s, from, to, msg;
XmlContent content;
ImxmlCharSequence const xml = "<msg from=\"John\" to=\"Jane\">Hello, World!</msg>"IMXML_LIT_PAD;
XmlParser p = {0};
p.head = xml;
imxml_strlit89(s, "msg");
assert(xml_tag_expect_str(&p, s));
imxml_strlit89(s, "from");
assert(xml_attr_expect_str(&p, s));
from = xml_value(&p);
imxml_strlit89(s, "to");
assert(xml_attr_expect_str(&p, s));
to = xml_value(&p);
content = xml_content(&p);
assert(content.type == XML_CONTENT_TEXT);
msg = content.data;
assert(xml_content(&p).type == XML_CONTENT_TAG);
printf("%.*s->%.*s: '%.*s'\n", (int)from.count, from.items, (int)to.count, to.items, (int)msg.count, msg.items);
return 0;
}
|