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.
47 lines
934 B
47 lines
934 B
16 years ago
|
/*! @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:
|
||
|
xml::Optional<int> a;
|
||
|
xml::Optional<std::string> txt;
|
||
|
protected:
|
||
|
void initXmlMembers() {
|
||
|
className("A");
|
||
|
persist(a, "a");
|
||
|
persist(txt, "txt");
|
||
|
}
|
||
|
};
|
||
|
|
||
|
class B: public xml::Serialize {
|
||
|
public:
|
||
|
xml::Optional<A> a;
|
||
|
xml::Optional<int> i;
|
||
|
xml::Optional<std::string> txt;
|
||
|
protected:
|
||
|
void initXmlMembers() {
|
||
|
className("B");
|
||
|
persist(a, "a");
|
||
|
persist(i, "i");
|
||
|
persist(txt, "txt");
|
||
|
}
|
||
|
};
|
||
|
|
||
|
int main(int, char**) {
|
||
|
{ // Serialization as a member
|
||
|
std::stringstream ss("<B/>");
|
||
|
B b;
|
||
|
b.loadXml(ss);
|
||
|
b.saveXml(std::cout)<<std::endl;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|