master
Marc Wäckerlin 15 years ago
parent d67a7d2c95
commit c16fe5421e
  1. 42
      doc/examples/list_serialization.cxx

@ -0,0 +1,42 @@
/*! @file
@id $Id: inherit_serialization.cxx 26 2009-04-24 07:13:10Z $
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
// g++ -I../../src ../../src/xml.cxx list_serialization.cxx
#include <xml-cxx/xml.hxx>
#include <iostream>
#include <sstream>
#include <list>
class A: public xml::Serialize {
public:
std::list<std::string> list;
protected:
void initXmlMembers() {
className("A");
persist(list, "list", "item");
}
};
int main(int, char**) {
std::stringstream ss("<A>\n"
"\t<list>\n"
"\t\t<item>Hello</item>\n"
"\t\t<item>World</item>\n"
"\t\t<item>how</item>\n"
"\t\t<item>are</item>\n"
"\t\t<item>you</item>\n"
"\t</list>\n"
"</A>");
A a;
std::cout<<"Schema:\n"<<a.schema()<<std::endl;
a.loadXml(ss);
if (a.list.front()=="Hello") a.list.front()="Good Bye";
if (a.list.back()=="you") a.list.back()="we";
a.saveXml(std::cout)<<std::endl;
return 0;
}
Loading…
Cancel
Save