/*! @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;
  protected:
    void initXmlMembers() {
      className("A");
      persist(list, "list");
    }
};

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");
    }
};

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;
  return 0;
}
