欢迎访问铁路通信信号工程技术,今天是 English

铁路通信信号工程技术 ›› 2021, Vol. 18 ›› Issue (2): 88-92.DOI: 10.3969/j.issn.1673-4440.2021.02.019

• • 上一篇    下一篇

基于QT的XML文件自动转换方法

王宏明,林卫永,王泉荣,温业中   

  1. 通号万全信号设备有限公司,杭州 310000
  • 收稿日期:2019-04-28 修回日期:2019-10-29 出版日期:2021-02-25 发布日期:2021-08-18

QT-based Automatic Conversion Method of XML Files

Wang Hongming,  Lin Weiyong,  Wang Quanrong,  Wen Yezhong   

  1. CRSC Wanquan Signal Equipment Co., Ltd., Hangzhou    310000, China
  • Received:2019-04-28 Revised:2019-10-29 Online:2021-02-25 Published:2021-08-18

摘要: 为简单方便的将XML文件转换为C++的对象实例,提出一种将XML文件和C++对象之间互相转换的方法。研究XML文件的结构和QT的元类型系统,以XML根节点为开始,采用深度优先读取算法遍历XML文件的每个节点,将节点内容和节点属性组装到C++对象实例,保留XML文件的元素间的嵌套关系,可以根据该关系读取整个XML文档,也可以根据需要只读取对应节点的内容。最后通过实例验证该方法的正确性和有效性,演示该方法的简单、高效。

关键词: 可扩展标记语言, XML, QT, 转换, 类, C++, 动态实例, 元类型系统

Abstract: 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-first reading algorithm. The content and attributes of node are assembled into C++ object instances. The nested relationship among elements of XML file is preserved. The whole XML file 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 efficiency.

Key words: extensible markup language, XML, QT, conversion, class, C++, dynamic instance, metatype system

中图分类号: