XML数据绑定-可以自动完成读/写功能
gSoap XML data binding - Possible to auto complete read/write functions?
我使用了几个XML文件,每个文件都有自己的处理程序类。每个类都有loadXML和exportXML函数,它们除了一行之外是相同的。我想确定一种方法,在这种方法中,每次为新的XML创建新的处理程序类时都不必复制和粘贴。
对于每个文件,我只修改:
if(soap_read__gt__Library(&soap, &library) != SOAP_OK)
和
if(soap_write__gt__Library(&soap, &library) != SOAP_OK)
gt是命名空间,Library是根节点。每个新的XML文件都有不同的名称空间和根节点。这些现在在编译之前,是否有任何方式来自动替换每个类加载/导出xml函数与他们尊重的名称空间和根节点?
。我用名称空间test和根节点devConfig创建了一个新的xml。我想用soap_read_test__devconfig和soap_write_test__devConfig替换load/exportXML的方法。
void LoadXML(struct soap& soap, _gt__Library& library, const string& strXMLPath)
{
ifstream fstreamIN(strXMLPath);
soap.is = &fstreamIN;
// calls soap_begin_recv, soap_get__gt__Library and soap_end_recv
if(soap_read__gt__Library(&soap, &library) != SOAP_OK)
{
std::cout << "soap_read__gt__Library() failed" << std::endl;
throw 1;
}
// patch
if(_setmode(_fileno(stdin), _O_TEXT) == -1)
{
std::cout << "_setmode() failed" << std::endl;
throw 1;
}
// ~patch
}
void exportXML(struct soap& soap, _gt__Library& library, const string& strXMLPath)
{
soap_set_omode(&soap, SOAP_XML_INDENT);
ofstream fstreamOUT(strXMLPath);
soap.os = &fstreamOUT;
// calls soap_begin_send, soap_serialize, soap_put and soap_end_send
if(soap_write__gt__Library(&soap, &library) != SOAP_OK)
{
std::cout << "soap_write__gt__Library() failed" << std::endl;
throw 1;
}
}
可能不是最干净的解决方案,但我想你可以使用宏,像这样:
#define loadXML(soap, gt_name, library, namespaces, root, strXMLPath)
ifstream fstreamIN(strXMLPath);
soap.is = &fstreamIN;
soap_set_namespaces(soap, namespaces); // namespace table
if(soap_begin_recv(soap) ||
soap_get_##gt_name(soap, library, root, NULL)) ||
soap_end_recv(soap))
{
std::cout << "soap_read__gt__Library() failed" << std::endl;
throw 1;
}
etc.
并展开它以实现您想要的操作:
loadXML(&soap, gt__library, &library, namespaces, "some-root", strXMLPath)
相关文章:
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 编译器如何在编译时执行数据绑定?
- 学生信息的数据绑定
- 使用提升功能与地图绑定提升
- 绑定和提升功能
- 为什么VAO可以使用VBO数据绑定它?
- C++ 由于无法解决过载功能而导致绑定失败
- C 使用多个lambdas/绑定以引用相同的功能
- 实现功能对象绑定而无需使用C 11
- 尝试将简单按钮绑定到SFGUI中的OnClick功能
- 从高度动态的C 数据模型中更新QML:计时器与属性绑定
- 绑定std ::功能错误
- DDX 数据绑定与 Windows 窗体找不到类方法
- 代码合成XSD解析/数据绑定xml字符串,而不是xml文件
- 请帮助我检查Silverlight for Windows Embedded中有关数据绑定的代码
- XML数据绑定-可以自动完成读/写功能
- c++中的XML数据绑定,具有简单的非侵入性数据模型
- C++的XML数据绑定,类似于java的JAXB
- Windows 8 APP,用数据绑定改变XAML文本框的文本.游戏循环工作线程导致问题
- 数据绑定- XML数据绑定和c++代码生成器