正在分析XML中C/C++头文件中定义的嵌套结构/联合
Parsing Nested Structures/Unions defined in C/C++ header files in XML
我有一个如下所示的结构:(示例)
struct struct3
{
struct structchild4
{
float child5;
} child6;
unsigned int child7;
};
我希望这在XML中表示如下:
<tag1= "struct3">
<name>struct3</name>
<input_type>byte</input_type>
<method></method>
<tag_ref = "structchild4">
<name>child6</name>
</tag_ref>
<tag2= "child7">
<name>child7</name>
<len>4</len>
<value> </value>
</tag2>
</tag1>
我所遵循的方法是将其转换为gccXML格式,然后使用Visual C++对其进行解析。我使用xerces-c DOM解析器。
有人能建议怎么做吗?谢谢
更好的方法是反射,BoostLib有一些现成的。你做的事情像:
for( Attribute::Iterator it = reflectiveObject.getAttributeList().begin();
it != reflectiveObject.getAttributeList().end();
++it )
{
XML.createNode( it.getAttributeName() );
}
//那么方法也是如此。应该有一个递归遍历类型的上层迭代器,如果类型有一个子类或子结构,那么识别XML并为它们运行相同的代码。
没有反射会更无聊,你应该为它创建一个格式化程序和一个解析器,比如
if( dynamic_cast< DesirecClass* >( obj ) != NULL ){
XML.createNode( typeid( obj ).name() );
}
// Hard Code (terrible treatment) for each attribute, etc...
还有一些可以搜索的解映射方法。
相关文章:
- 告诉CMake链接到自定义文件夹中的Boost
- 通过cMake使用具有自定义文件扩展名的共享库
- 威纳派读取自定义文件或文件夹的所有访问权限
- 使用命令列表解析自定义文件
- 单独的类声明和方法定义文件问题
- Qt解析自定义文件格式
- 将单独的头文件和类定义文件链接到主函数文件 - G++ 返回重载"undefined reference to"构造函数
- FAT32和NTF中的自定义文件属性
- 如何在没有"fatal error: Wt/WApplication: No such file or directory"的情况下将wt安装到自定义文件夹中
- C++ while 循环在自定义文件结构中
- QT C 读取自定义文件结构
- gcc 是否有编译指示来定义文件类型/编译器
- C/C++ 中的跨平台自定义文件头
- 使用头文件和类定义文件时未解决的外部符号错误
- 将此c++代码分解为单独的类规范文件和函数定义文件
- 自定义文件类中fstream对象的生存期
- 如何使用BinaryReader类使用C#读取自定义文件(C++)
- 提供带有libjpeg的自定义文件IO
- C++模块定义文件头内联符号
- 错误:未定义文件中的第一个引用符号