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.

92 lines
3.1 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
#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() {
className("A");
persist(list, "list");
16 years ago
}
};
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");
}
};
16 years ago
int main(int, char**) {
std::stringstream ss("<B>"
" <b>1234</b>"
" <a>"
" <list>"
" <item>guguseli</item>"
" </list>"
" </a>"
" <As>"
" <A>"
" <list>"
" <item>Hello</item>"
" <item>World</item>"
" <item>how</item>"
" <item>are</item>"
" <item>you</item>"
" </list>"
" </A>"
" <A>"
" <list>"
" <item>a</item>"
" <item>b</item>"
" <item>c</item>"
" <item>d</item>"
" <item>e</item>"
" </list>"
" </A>"
" <A>"
" <list>"
" <item>f</item>"
" <item>g</item>"
" <item>h</item>"
" <item>i</item>"
" <item>j</item>"
" </list>"
" </A>"
" <A>"
" <list>"
" <item>k</item>"
" <item>l</item>"
" <item>m</item>"
" <item>n</item>"
" <item>o</item>"
" </list>"
" </A>"
" </As>"
"</B>");
B b;
std::cout<<"SCHEMA:"<<std::endl<<b.schema()<<std::endl;
b.loadXml(ss);
if (b.as.front().list.front()=="Hello") b.as.front().list.front()="Good Bye";
if (b.as.front().list.back()=="you") b.as.front().list.back()="we";
b.saveXml(std::cout)<<std::endl;
16 years ago
return 0;
}