summaryrefslogtreecommitdiff
path: root/examples/simple.c
diff options
context:
space:
mode:
authorsteven-vd <steven@vandorp.lu>2026-08-16 15:00:32 +0200
committersteven-vd <steven@vandorp.lu>2026-08-17 09:31:42 +0200
commitee081ca70322cd01d0642fdb1860e6bfbfb48e85 (patch)
tree295fdba93b08b24562c6d49e971bbf3425eac50c /examples/simple.c
Initial commitHEAD0.1.0master
Diffstat (limited to 'examples/simple.c')
-rw-r--r--examples/simple.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/simple.c b/examples/simple.c
new file mode 100644
index 0000000..caacc83
--- /dev/null
+++ b/examples/simple.c
@@ -0,0 +1,27 @@
+#include <assert.h>
+#include <stdio.h>
+#define ASSERT assert
+#define IMXML_SIMD_DEFAULT SSE2
+#define IMXML_IMPLEMENTATION
+#include "imxml.h"
+
+int main (void) {
+ ImxmlCharSequence const xml = "<msg from=\"John\" to=\"Jane\">Hello, World!</msg>"IMXML_LIT_PAD;
+ XmlParser p = {
+ .head = xml,
+ };
+
+ assert(xml_tag_expect(&p, "msg"));
+ assert(xml_attr_expect(&p, "from"));
+ ImxmlString const from = xml_value(&p);
+ assert(xml_attr_expect(&p, "to"));
+ ImxmlString const to = xml_value(&p);
+
+ XmlContent content = xml_content(&p);
+ assert(content.type == XML_CONTENT_TEXT);
+ ImxmlString 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);
+}
+