new file
This commit is contained in:
42
doc/examples/list_serialization.cxx
Normal file
42
doc/examples/list_serialization.cxx
Normal file
@@ -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;
|
||||
}
|
Reference in New Issue
Block a user