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.

44 lines
1.2 KiB

16 years ago
/*! @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:
xml::List<std::string> list;
16 years ago
protected:
void initXmlMembers() {
LOG("A::initXmlMembers");
16 years ago
className("A");
persist(list, "list");
16 years ago
}
};
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";
16 years ago
a.saveXml(std::cout)<<std::endl;
return 0;
}