Ah, I just noticed you mentioned the only important bit here, hidden in a small aside:
main.cpp (from the tutorial but with xml archives)
Xml archives need names for their elements!
Name-Value Pairs
XML archives present a somewhat special case. XML format has a nested structure that maps well to the "recursive class member visitor" pattern used by the serialization system. However, XML differs from other formats in that it requires a name for each class data member. Our goal is to add this information to the class serialization specification while still permiting the the serialization code to be used with any archive.
Our solution is to wrap class members to be serialized in a name-value-pair. This structure is defined in nvp.hpp. It is just a reference to the data member coupled with a pointer to to a const char * which corresponds to the XML name. It implements the default serialization functions for a name-value pair. This default action is to just ignore the item name and serialize the data value in the normal manner. For archive classes that don't make any special provision for name-value pairs, this is the action which will be invoked when the name-value pair is serialized. Hence, wrapping a data value into a name-value pair will have no effect when used with archives which make no special provision for this wrapper.
See, looking at demo_xml.cpp
, add:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(degrees);
ar & BOOST_SERIALIZATION_NVP(minutes);
ar & BOOST_SERIALIZATION_NVP(seconds);
}
and
boost::archive::xml_oarchive oa(ofs);
// write class instance to archive
oa << BOOST_SERIALIZATION_NVP(g);
See it Live on Coliru
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="10">
<g class_id="0" tracking_level="0" version="0">
<degrees>35</degrees>
<minutes>59</minutes>
<seconds>24.566999</seconds>
</g>
</boost_serialization>