Boost logo

Boost Users :

From: Ruediger Berlich (ruediger.berlich_at_[hidden])
Date: 2007-04-16 17:54:06


Hi there,

I've got the problem that the XML description of my serialized classes seem
to be missing the final closing tag. Funnily enough loading of the XML
descriptions nevertheless works.

The platform is OpenSUSE 10.2, g++ 4.1.2, Boost 1.33.1 .

I'll try to illustrate the problem with a small program. Output further
below.

/************************************************************************/
// headers + namespace statements removed to save space

class test
{
    friend class boost::serialization::access;
    
    template<class Archive>
    void serialize(Archive & ar, const unsigned int version){
        using boost::serialization::make_nvp;
        ar & make_nvp("x",x);
    }

    int x;

public:
    test(int i){ x = i; }
    void printX(void){ cout << "x = " << x << endl; }
};

main()
{
    test Test(1);

    // I want a stringstream, as my applicion is in remote processing
    ostringstream oss;
    assert(oss.good());
    boost::archive::xml_oarchive oa(oss);
    oa << BOOST_SERIALIZATION_NVP(Test);

    // Closing tag is missing in output, see below
    cout << oss.str() << flush;

    // But the file has the correct content, see below
    ofstream ofs("print.xml");
    assert(ofs.good());
    boost::archive::xml_oarchive oa2(ofs);
    oa2 << BOOST_SERIALIZATION_NVP(Test);

    // Try to load the incorrect XML description works !?!??
    test Test2(2);
    istringstream iss(oss.str());
    assert(iss.good());
    boost::archive::xml_iarchive ia(iss);
    ia >> BOOST_SERIALIZATION_NVP(Test2);
    // Funnily enough this seems to work
    Test2.printX(); // correctly prints "x = 1", not "x = 2"
}

/************************************************************************/

So when I give the xml_oarchive an ostringstream as argument (because my
application is in remote processing and I don't need file output), the
result is:

/************************************************************************/

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="3">
<Test class_id="0" tracking_level="0" version="0">
        <x>1</x>
</Test>

/************************************************************************/

So here the closing tag </boost_serialization> is missing. If I do the same
with an ofstream (see program) the file content is o.k. .

/************************************************************************/

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="3">
<Test class_id="0" tracking_level="0" version="0">
        <x>1</x>
</Test>
</boost_serialization>

/************************************************************************/

Funnily enough my problem with the ostringstream does not seem to have an
influence on the loading of the XML description.

What am I doing wrong ?

Thanks and Best Regards,
Ruediger


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