48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
/*! @file
|
|
|
|
@id $Id$
|
|
*/
|
|
// 1 2 3 4 5 6 7 8
|
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
|
#include <xml-cxx/xml.hxx>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
|
|
class A: public xml::Serialize {
|
|
public:
|
|
int a;
|
|
std::string txt;
|
|
protected:
|
|
void initXmlMembers() {
|
|
className("A");
|
|
persist(a, "a");
|
|
persist(txt, "txt");
|
|
}
|
|
};
|
|
|
|
class B: public A { // A inherits xml::Serialize, B inherits A
|
|
public:
|
|
int b;
|
|
protected:
|
|
void initXmlMembers() {
|
|
A::initXmlMembers(); // <- Here is the important difference
|
|
className("B");
|
|
persist(b, "b");
|
|
}
|
|
};
|
|
|
|
int main(int, char**) {
|
|
std::stringstream ss("<B>\n"
|
|
"\t<b>1234</b>\n"
|
|
"\t<a>5678</a>\n"
|
|
"\t<txt>Dies ist ein Serialisierungs-Test</txt>\n"
|
|
"</B>");
|
|
B b;
|
|
b.loadXml(ss);
|
|
if (b.b==1234) b.b=4321;
|
|
if (b.a==5678) b.a=8765;
|
|
b.saveXml(std::cout)<<std::endl;
|
|
return 0;
|
|
}
|