Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] removing excess XML tags
From: Maarten Nieber (hallomaarten_at_[hidden])
Date: 2009-02-10 09:01:38


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 <paul.heil_at_[hidden]>
To: boost-users_at_[hidden]
Sent: Thursday, February 5, 2009 9:35:55 PM
Subject: Re: [Boost-users] [serialization] removing excess XML tags

On Thu, Feb 5, 2009 at 2:16 PM, John Pretz <jpretz_at_[hidden]> wrote:

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 <boost/archive/xml_oarchive.hpp>

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>
   <boost_serialization signature="serialization::archive" version="5">
   <MYTAG class_id="0" tracking_level="0" version="0"></MYTAG>
   </boost_serialization>

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_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
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

      



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