[serialization] removing excess XML tags
I'd like to use the boost::serialization library to generate XML that must
be read by a third party application. Unfortunately, this application does
not like the extra stuff that the serialization library generates.
The code below generates XML that looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
Paul,
You can turn off the wrapping boost_serialization tag by giving your
archive the boost::archive::no_header switch. There's a
boost::archive::no_tracking switch, but it doesn't seem to turn off the
'class_id' and 'tracking_level' stuff.
John
#include <fstream>
#include <iostream>
#include
I'd like to use the boost::serialization library to generate XML that must be read by a third party application. Unfortunately, this application does not like the extra stuff that the serialization library generates.
The code below generates XML that looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<MYTAG class_id="0" tracking_level="0" version="0"></MYTAG> What I need is XML that looks more like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <MYTAG></MYTAG>
What can I do to eliminate the extra stuff?
Thanks, PaulH
class MyClass { private: friend class boost::serialization::access;
template<class Archive> void serialize(Archive &ar, const unsigned int version){};
public: MyClass(){}; friend std::ostream & operator<<(std::ostream &os, const MyClass &gp); virtual ~MyClass(){}; };
int main( int argc, _TCHAR* argv[] ) { MyClass mc;
std::ofstream ofs("MyFile.xml"); boost::archive::xml_oarchive oa(ofs); oa << boost::serialization::make_nvp( "MYTAG", mc );
return 0; } ------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Thu, Feb 5, 2009 at 2:16 PM, John Pretz
Paul,
You can turn off the wrapping boost_serialization tag by giving your archive the boost::archive::no_header switch. There's a boost::archive::no_tracking switch, but it doesn't seem to turn off the 'class_id' and 'tracking_level' stuff.
John
#include <fstream> #include <iostream> #include
class MyClass { private: friend class boost::serialization::access;
template<class Archive> void serialize(Archive &ar, const unsigned int version){};
public: MyClass(){}; friend std::ostream & operator<<(std::ostream &os, const MyClass &gp); virtual ~MyClass(){}; };
int main( int argc, char** argv[] ) { MyClass mc;
// std::ofstream ofs("MyFile.xml"); boost::archive::xml_oarchive oa(std::cout,boost::archive::no_header); oa << boost::serialization::make_nvp( "MYTAG", mc );
return 0; }
Paul Heil wrote:
I'd like to use the boost::serialization library to generate XML that must be read by a third party application. Unfortunately, this application does not like the extra stuff that the serialization library generates.
The code below generates XML that looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<MYTAG class_id="0" tracking_level="0" version="0"></MYTAG> What I need is XML that looks more like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <MYTAG></MYTAG>
What can I do to eliminate the extra stuff?
Thanks, PaulH
class MyClass { private: friend class boost::serialization::access;
template<class Archive> void serialize(Archive &ar, const unsigned int version){};
public: MyClass(){}; friend std::ostream & operator<<(std::ostream &os, const MyClass &gp); virtual ~MyClass(){}; };
int main( int argc, _TCHAR* argv[] ) { MyClass mc;
std::ofstream ofs("MyFile.xml"); boost::archive::xml_oarchive oa(ofs); oa << boost::serialization::make_nvp( "MYTAG", mc );
return 0; } ------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Unfortunately, the "no_header" flags turns off the xml version header which I actually do need to keep: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> -PaulH
Hi Paul,
maybe you could use the no_header switch and paste the XML header into the file in a post-processing step?
Best,
Maarten
________________________________
From: Paul Heil
Make your own archive derived from xml_?archive.
Robert Ramey
"Paul Heil"
The extra headers from Boost::serialisation are consistent and are well-formed XML. Couldn't you write some code to strip that out at the end?
Damien
_____
From: Robert Ramey [mailto:ramey@rrsd.com]
To: boost-users@lists.boost.org
Sent: Thu, 05 Feb 2009 13:47:27 -0700
Subject: Re: [Boost-users] [serialization] removing excess XML tags
Make your own archive derived from xml_?archive.
Robert Ramey
"Paul Heil"
On Thu, Feb 5, 2009 at 2:53 PM, Damien Hocking
The extra headers from Boost::serialisation are consistent and are well-formed XML. Couldn't you write some code to strip that out at the end?
Damien
I could... But that seems inefficient. I'd rather just have it work the way I want in the first place. If it comes down to that, I'll probably use something other than Boost.Serialize to do this. Thanks
On Thu, Feb 5, 2009 at 2:47 PM, Robert Ramey
Make your own archive derived from xml_?archive.
Robert Ramey
"Paul Heil"
wrote in message news:2fc4ff370902051118v6b811275rdad4dd46c04d40c9@mail.gmail.com... I'd like to use the boost::serialization library to generate XML that must be read by a third party application. Unfortunately, this application does not like the extra stuff that the serialization library generates. The code below generates XML that looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<MYTAG class_id="0" tracking_level="0" version="0"></MYTAG> What I need is XML that looks more like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <MYTAG></MYTAG>
What can I do to eliminate the extra stuff?
Thanks, PaulH
class MyClass { private: friend class boost::serialization::access;
template<class Archive> void serialize(Archive &ar, const unsigned int version){};
public: MyClass(){}; friend std::ostream & operator<<(std::ostream &os, const MyClass &gp); virtual ~MyClass(){}; };
int main( int argc, _TCHAR* argv[] ) { MyClass mc;
std::ofstream ofs("MyFile.xml"); boost::archive::xml_oarchive oa(ofs); oa << boost::serialization::make_nvp( "MYTAG", mc );
return 0; }
------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
That looks like the right way to go if I'm going to use Boost.Serialize to do this. I guess I was hoping I was just missing a flag or something easy. I'm not really looking to re-implement that much stuff. Thanks
On Thu, Feb 05, 2009 at 01:18:00PM -0600, Paul Heil wrote:
I'd like to use the boost::serialization library to generate XML that must be read by a third party application. Unfortunately, this application does not like the extra stuff that the serialization library generates.
The code below generates XML that looks like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <!DOCTYPE boost_serialization>
<MYTAG class_id="0" tracking_level="0" version="0"></MYTAG> What I need is XML that looks more like this: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <MYTAG></MYTAG>
What can I do to eliminate the extra stuff?
Thanks, PaulH
Hi Paul You could post-process the Boost output with XSLT to remove the unwanted tags? There may be a way to do it within Boost::Serialization but I do not know. Bob
Hi Paul,
Maybe some sed script could help:
Hint (Sorry, I'm not a sed guru!):
cat file.xml | sed \
-e '/^<!DOCTYPE boost_serialization>$/d' \
-e '/^
participants (7)
-
Bob Wilkinson
-
Damien Hocking
-
Francois Mauger
-
John Pretz
-
Maarten Nieber
-
Paul Heil
-
Robert Ramey