Module dlib.serialization.xml

GC-free parser for a subset of XML.

Description

Has the following limitations: - supports only ASCII and UTF-8 encodings - doesn't support DOCTYPE and some other special tags

Example

string xml = "
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<object>
    <property name=\"position\" value=\"0 10 5\"/>
    <!-- comment -->
    <![CDATA[ some data ]]>
    <foo>&#xE9;</foo>
</object>
";

XmlDocument doc = parseXMLUnmanaged(xml);

assert(doc.prolog.properties["version"] == "1.0");
assert(doc.prolog.properties["encoding"] == "UTF-8");

auto obj = doc.root.children[0];
assert(obj.name == "object");

auto p = obj.children[0];
assert(p.name == "property");
assert(p.properties["name"] == "position");
assert(p.properties["value"] == "0 10 5");

assert(prop(p, "name") == "position");
assert(prop(p, "something") == "");

auto foo = obj.firstChildByTag("foo");
assert(foo.name == "foo");

string fooText = foo.getTextUnmanaged();
assert(fooText == "é");
Delete(fooText);

Delete(doc);

Example

assert(hexCharacterCode("ff00ff") == 16711935);
assert(hexCharacterCode("ABABAB;") == 11250603);