摘要
为简单方便的将XML文件转换为C++的对象实例,提出一种将XML文件和C++对象之间互相转换的方法。研究XML文件的结构和Q T的元类型系统,以XML根节点为开始,采用深度优先读取算法遍历XML文件的每个节点,将节点内容和节点属性组装到C++对象实例,保留XML文件的元素间的嵌套关系,可以根据该关系读取整个XML文档,也可以根据需要只读取对应节点的内容。最后通过实例验证该方法的正确性和有效性,演示该方法的简单、高效。
In order to convert XML files into object instances of C++,this paper presents an interconversion method between XML files and C++objects.The structure of XML file and the metatype system of QT are studied.Starting with the XML root node,each node of XML file is traversed by depth-fi rst reading algorithm.The content and attributes of node are assembled into C++object instances.The nested relationship among elements of XML fi le is preserved.The whole XML fi le can be read according to this relationship,or only the content of the corresponding node can be read as needed.Finally,an example is given to verify the correctness and validity of the method and demonstrate its simplicity and effi ciency.
作者
王宏明
林卫永
王泉荣
温业中
Wang Hongming;Lin Weiyong;Wang Quanrong;Wen Yezhong(CRSC Wanquan Signal Equipment Co.,Ltd.,Hangzhou 310000,China)
出处
《铁路通信信号工程技术》
2021年第2期88-92,共5页
Railway Signalling & Communication Engineering