C++ class for reading and writing XML structures. No need for a C++ code parser or special pre compiler. Specify a schema entirly in native C++. The schema is verified when XML is read and exceptions are thrown when the XML to be parse is invalid.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.0 KiB

/*! @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;
}