Hi,
I am able to insert the stylesheet tag from inside a constructor of my new derived class. Please find below the whole program. But, I am still getting an error : terminate called after throwing an instance of 'std::bad_cast' what(): std::bad_cast Aborted (core dumped) on the statement : xa << BOOST_SERIALIZATION_NVP(e); in the code below. The statements : xa.putTag ("TESTING_XMLCLASS"); xa << BOOST_SERIALIZATION_NVP(tmp); oa << BOOST_SERIALIZATION_NVP(e); work as expected. Can you please let me know what could be the reason for this? Regards, Girish # include <iostream> #include <fstream> #include <string> #include <boost/archive/tmpdir.hpp> #include <boost/archive/xml_oarchive.hpp> #include <boost/serialization/nvp.hpp> #include <boost/serialization/utility.hpp> #include <boost/serialization/version.hpp> #include <boost/archive/xml_oarchive.hpp> using namespace std; using namespace boost::archive; struct EMPLOYEE { int id; string name; friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int /* file_version */) { ar << BOOST_SERIALIZATION_NVP(id); ar << BOOST_SERIALIZATION_NVP(name); } }; class XMLArchive : public xml_oarchive_impl<xml_oarchive> { public : XMLArchive (ostream &os) : xml_oarchive_impl<xml_oarchive>(os, 0) { os.seekp (58); string styletag = "?xml-stylesheet type=\"text/xsl\" href=\"XSLTFile.xsl\"?>\n"; string line1 = "<!DOCTYPE boost_serialization>\n"; string line2 = "<boost_serialization signature=\"serialization::archive\" version=\"5\">\n"; string buffer = styletag + line1 + line2; os << buffer; os.flush (); } void putTag (string tagname) { string tag_str = "<"; tag_str = tag_str + tagname + ">\n"; os << tag_str; } ~XMLArchive () {} }; int main (void) { ofstream ofs ("XMLresult.xml"); XMLArchive xa(ofs); // boost::archive::xml_oarchive oa(ofs); xa.putTag ("TESTING_XMLCLASS"); string tmp = "TMPTMP"; xa << BOOST_SERIALIZATION_NVP(tmp); struct EMPLOYEE e; e.id = 101; e.name = "James Bond"; xa << BOOST_SERIALIZATION_NVP(e); // oa << BOOST_SERIALIZATION_NVP(e); return 0; } --- On Thu, 2/18/10, Robert Ramey <ramey@rrsd.com> wrote:
|