You are hereBoost XML Serialization hints

Boost XML Serialization hints


By admin - Posted on 09 Mai 2011

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!

Registered users can add comments to the articles. The registration process requires verification using an arbitrary email adress. Comments are moderated and spam of any form will not be published (spammers do not try - you have no chance).

Registrierte Benutzer können Kommentare zu den Artikeln schreiben. Die für die Registrierung erforderliche Authentifizierung erfolgt über eine beliebige Email Adresse. Kommentare werden erst nach erfolgter Durchsicht veröffentlicht um Spam zu verhindern.