XML Archiver

The ArchiverXml class provides an implementation to serialize to and from XML files.

Design

The XML archiver is powered by TinyXML2.

Settings

The XML archiver provides several settings to customize the XML output.

The effect of each setting will be shown based on the following XML output (unless noted otherwise):

<?xml version="1.0" encoding="utf-8"?>
<!--All of our cars:-->
<cars>
    <!--One of our cars:-->
    <car>
        <color format="rgb" name="Gray">
            <blue depth="32">50</blue>
            <green depth="32">50</green>
            <red depth="32">50</red>
        </color>
        <manufacturer>Audi</manufacturer>
        <model>A6</model>
        <year_of_construction>2015</year_of_construction>
    </car>
    <!--One of our cars:-->
    <car>
        <color format="rgb" name="Black">
            <blue depth="32">0</blue>
            <green depth="32">0</green>
            <red depth="32">0</red>
        </color>
        <manufacturer>Jeep</manufacturer>
        <model>Grand Cherokee</model>
        <year_of_construction>2009</year_of_construction>
    </car>
</cars>

Print comments

The print_comments settings allow to control whether the value and container comments should be shown in the XML output.

Setting this to false will tell the archiver to omit all comments:

<?xml version="1.0" encoding="utf-8"?>
<cars>
    <car>
        <color format="rgb" name="Gray">
            <blue depth="32">50</blue>
            <green depth="32">50</green>
            <red depth="32">50</red>
        </color>
        <manufacturer>Audi</manufacturer>
        <model>A6</model>
        <year_of_construction>2015</year_of_construction>
    </car>
    <car>
        <color format="rgb" name="Black">
            <blue depth="32">0</blue>
            <green depth="32">0</green>
            <red depth="32">0</red>
        </color>
        <manufacturer>Jeep</manufacturer>
        <model>Grand Cherokee</model>
        <year_of_construction>2009</year_of_construction>
    </car>
</cars>

Annotate types

Whether types should be annotated by using XML attributes.

Setting this to true will tell the archiver to annotate all element types:

<?xml version="1.0" encoding="utf-8"?>
<!--All of our cars:-->
<cars type="nested">
    <!--One of our cars:-->
    <car type="nested">
        <color format="rgb" name="Gray" type="nested">
            <blue depth="32" type="int">50</blue>
            <green depth="32" type="int">50</green>
            <red depth="32" type="int">50</red>
        </color>
        <manufacturer type="string">Audi</manufacturer>
        <model type="string">A6</model>
        <year_of_construction type="int">2015</year_of_construction>
    </car>
    <!--One of our cars:-->
    <car type="nested">
        <color format="rgb" name="Black" type="nested">
            <blue depth="32" type="int">0</blue>
            <green depth="32" type="int">0</green>
            <red depth="32" type="int">0</red>
        </color>
        <manufacturer type="string">Jeep</manufacturer>
        <model type="string">Grand Cherokee</model>
        <year_of_construction type="int">2009</year_of_construction>
    </car>
</cars>

Annotate list count

Controls whether the element count should be annotated in a list (sequence of elements).

This can be useful for more advanced parsers as this can be used to optimize memory allocation.

If set to false:

<cars>
    <car/>
    <car/>
    <car/>
</cars>

If set to true:

<cars count="3">
    <car/>
    <car/>
    <car/>
</cars>

Prefix annotations

Controls whether the various annotations such as type and list annotations (XML attributes) should be prefixed with the gpds namespace.

If set to false:

<?xml version="1.0" encoding="utf-8"?>
<!--All of our cars:-->
<cars type="nested" gpds:count="2">
    <!--One of our cars:-->
    <car type="nested">
        <color format="rgb" name="Gray" type="nested">
            <blue depth="32" type="int">50</blue>
            <green depth="32" type="int">50</green>
            <red depth="32" type="int">50</red>
        </color>
        <manufacturer type="string">Audi</manufacturer>
        <model type="string">A6</model>
        <year_of_construction type="int">2015</year_of_construction>
    </car>
    <!--One of our cars:-->
    <car type="nested">
        <color format="rgb" name="Black" type="nested">
            <blue depth="32" type="int">0</blue>
            <green depth="32" type="int">0</green>
            <red depth="32" type="int">0</red>
        </color>
        <manufacturer type="string">Jeep</manufacturer>
        <model type="string">Grand Cherokee</model>
        <year_of_construction type="int">2009</year_of_construction>
    </car>
</cars>

If set to true:

<?xml version="1.0" encoding="utf-8"?>
<!--All of our cars:-->
<cars gpds:type="nested" gpds:count="2">
    <!--One of our cars:-->
    <car gpds:type="nested">
        <color format="rgb" name="Gray" gpds:type="nested">
            <blue depth="32" gpds:type="int">50</blue>
            <green depth="32" gpds:type="int">50</green>
            <red depth="32" gpds:type="int">50</red>
        </color>
        <manufacturer gpds:type="string">Audi</manufacturer>
        <model gpds:type="string">A6</model>
        <year_of_construction gpds:type="int">2015</year_of_construction>
    </car>
    <!--One of our cars:-->
    <car gpds:type="nested">
    <color format="rgb" name="Black" gpds:type="nested">
        <blue depth="32" gpds:type="int">0</blue>
        <green depth="32" gpds:type="int">0</green>
        <red depth="32" gpds:type="int">0</red>
    </color>
    <manufacturer gpds:type="string">Jeep</manufacturer>
    <model gpds:type="string">Grand Cherokee</model>
    <year_of_construction gpds:type="int">2009</year_of_construction>
    </car>
</cars>