【发布时间】:2011-05-25 13:30:21
【问题描述】:
对于作为 .net Web 服务输入的对象序列化,我应该使用什么库(这意味着该 Web 服务需要在其输入中使用 xml)?
作为另一个问题:
如果使用非侵入式版本(引导序列化),在写入 xml 文件时,具体代码是什么? (oa<<?)。我尝试了一些解决方案,但似乎我有错误。我实际上不能说oa<< g.。
代码如下:
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <dlfcn.h>
#include <iostream>
#include <fstream>
class gps_position
{
public:
int degrees;
int minutes;
float seconds;
gps_position(){};
};
namespace boost { namespace serialization {
template<class Archive>
void serialize(Archive & ar, gps_position & g, const unsigned int version)
{
ar & g.degrees;
ar & g.minutes;
ar & g.seconds;
}
} } // namespace boost::serialization
// gps_position g;
int main() {
gps_position obj;
std::ofstream ofs("filename2.xml");
if(ofs.good()) {
//const gps_position g;
try {
boost::archive::xml_oarchive oa(ofs);
// what to write in the xml?
oa << ??????????????????;
} catch(boost::archive::archive_exception& ex) {
}
}
return 0;
}
【问题讨论】:
-
@mely 为您的问题使用适当的标签:您的问题被标记得越好,被看到的机会就越大。
-
您确定只需要序列化而不是完整的 C++ SOAP 工具包吗?
-
@mely:生成“一个 xml”是不够的。它必须符合 web 服务期望的任何格式(很可能是某种 SOAP)
-
@mely - 只是一个友好的建议:请不要使用答案来询问有关您要解决的问题的更多问题。而是更新您的问题或在评论中询问您需要一些小的说明。这样做会导致您失去声誉,因为这被视为糟糕的网站礼仪。
标签: c++ xml serialization