[Serialization] Closing tag in XML description missing

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>

try something like the following: 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); } // oa destructor invoked - puts end tag on archive ... }

Ah - that makes sense (and works). Thanks! Ruediger Robert Ramey wrote:
try something like the following:
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); } // oa destructor invoked - puts end tag on archive ... }
participants (2)
-
Robert Ramey
-
Ruediger Berlich