Boost logo

Boost Users :

Subject: [Boost-users] [serialization] empty xml output
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2011-03-26 19:41:19


Hi all,

I am trying to introduce XML serialization in my project, but even with the
simplest test, I cannot get something to work. Here is what I did:

#define PARAMETERS_HPP

 #include <boost/archive/xml_iarchive.hpp>

#include <boost/archive/xml_oarchive.hpp>

 #include <iostream>

 class rss_feeds_to_parse

{

public:

    bool all;

     template<class Archive> void serialize(Archive & ar, const
unsigned int file_version)

    {

        ar & BOOST_SERIALIZATION_NVP(all);

    }

};

 class parameters

{

public:

    rss_feeds_to_parse feeds;

     template<class Archive> void serialize(Archive & ar, const
unsigned int file_version)

    {

        ar & BOOST_SERIALIZATION_NVP(feeds);

    }

};

 #endif // PARAMETERS_HPP

Later, in my main, I have:

    parameters p;

    p.feeds.all = true;

    std::ofstream ofs("test_parameters.xml");

    assert(ofs.good());

    boost::archive::xml_oarchive oa(ofs);

    oa << BOOST_SERIALIZATION_NVP(p);

It compiles, links and executes well, the file test_parameters.xml is
created ... but empty !

What am I doing wrong?

Hope you could help.

Best regards,

Olivier



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net