2009-04-27 10:59:16 +00:00
|
|
|
/*! @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:
|
2009-04-29 11:58:57 +00:00
|
|
|
xml::List<std::string> list;
|
2009-04-27 10:59:16 +00:00
|
|
|
protected:
|
|
|
|
void initXmlMembers() {
|
|
|
|
className("A");
|
2009-04-29 11:58:57 +00:00
|
|
|
persist(list, "list");
|
2009-04-27 10:59:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-30 08:28:52 +00:00
|
|
|
class B: public xml::Serialize {
|
|
|
|
public:
|
|
|
|
int b;
|
|
|
|
A a;
|
|
|
|
xml::List<A> as;
|
|
|
|
protected:
|
|
|
|
void initXmlMembers() {
|
|
|
|
className("B");
|
|
|
|
persist(b, "b");
|
|
|
|
persist(a, "a");
|
|
|
|
persist(as, "As");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-27 10:59:16 +00:00
|
|
|
int main(int, char**) {
|
2009-04-30 08:28:52 +00:00
|
|
|
std::stringstream ss("<B>\n"
|
|
|
|
"<b>1234</b>"
|
|
|
|
"<a><list><item>guguseli</item></list></a>"
|
|
|
|
"<As>"
|
2009-04-30 15:10:09 +00:00
|
|
|
"<A>\n"
|
2009-04-27 10:59:16 +00:00
|
|
|
"\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"
|
2009-04-30 15:10:09 +00:00
|
|
|
"</A>"
|
2009-04-30 08:28:52 +00:00
|
|
|
"</As>"
|
|
|
|
"</B>");
|
|
|
|
B b;
|
|
|
|
std::cout<<"SCHEMA:"<<std::endl<<b.schema()<<std::endl;
|
|
|
|
b.loadXml(ss);
|
2009-04-29 11:58:57 +00:00
|
|
|
// if (a.list.front()=="Hello") a.list.front()="Good Bye";
|
|
|
|
// if (a.list.back()=="you") a.list.back()="we";
|
2009-04-30 08:28:52 +00:00
|
|
|
b.saveXml(std::cout)<<std::endl;
|
2009-04-27 10:59:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|