1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
//[ synopsis_xml_serialize
#include <fstream>
#include <zeep/xml/document.hpp>
struct Person
{
std::string firstname;
std::string lastname;
/*<< A struct we want to serialize needs a `serialize` method >>*/
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & zeep::make_nvp("firstname", firstname)
& zeep::make_nvp("lastname", lastname);
}
};
int main()
{
/*<< Read in a text document containing XML and parse it into a document object >>*/
std::ifstream file("test.xml");
zeep::xml::document doc(file);
std::vector<Person> persons;
/*<< Deserialize all persons into an array >>*/
doc.deserialize("persons", persons);
doc.clear();
/*<< Serialize all persons back into an XML document again >>*/
doc.serialize("persons", persons);
return 0;
}
//]
|