Boost XML Serialization hints

Whenever you use boost xml_oarchive, be careful that the closing archive xml tag is written whenever the archive gets destructed!

Therefore, the following won't work:


    std::string dumpXML()
    {
        std::stringstream stringstr_1;
        boost::archive::xml_oarchive xml_output_arch(stringstr);

        AnyClass& custom_data = m_custom;
        xml_output_arch  BOOST_SERIALIZATION_NVP(custom_data);

        return stringstr_1.str();
    }

A workaround is to introduce parenthesis to destroy the archive prior to returning the stringstream, like:

    std::string dumpXML()
    {
        std::stringstream stringstr_1;
        {
            boost::archive::xml_oarchive xml_output_arch(stringstr);

            AnyClass& custom_data = m_custom;
            xml_output_arch  BOOST_SERIALIZATION_NVP(custom_data);
        }
        return stringstr_1.str();
    }

It is also not possible to add comments to the XML serialized files, otherwise boost is not able to deserialize the files properly!

A problem can also be variable naming! It seems that boost writes the variable name of the variable that was serialized to the XML file and it may not be possible to deserialize the file to a variable of the same class with a different name!