我有许多看起来像这样的结构:
struct A
{
long lValueA;
BOOL bValueA;
CString strValueA;
};
struct B
{
long lValueB;
BOOL bValueB;
CString strValueB;
};
struct C
{
A a;
vector<B> vecB;
};
是否可以使用 TinyXML2 (或任何其他库)将其转换为 XML 文件,而无需从struct C手动传递每个成员变量?我想要的是这样的:
main()
{
C c;
// Some code to initialise member variable of struct C
// pass object/structure to XML parser to get XML file.
Some_XML_Library_Object.parse( c );
Some_XML_Library_Object.SaveFile("FilePath/Name.xml");
// Also it would be nice if we can update values in structure or class directly like this
const char* XML_File_Path = "FilePath/Name.xml";
Some_XML_Library_Object.updateValueOfStructureFromXML(&c,XML_File_Path)
}
XML 文件生成类似于以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<A>
<lValueA>
value
</lValueA>
<bValueA>
value
</bValueA>
<strValueA>
value
</strValueA>
</A>
<B>
<lValueB>
value
</lValueB>
...
...
</B>
提前致谢。