xsjqqq123 xsjqqq123
关注数: 11 粉丝数: 123 发帖数: 3,005 关注贴吧数: 49
c++如何将xml转成struct结构体,够挑战了吧~~ 楼主刚毕业入职,老总交一写配置界面的任务,需要在界面上增删修改配置,然后保存到xml,原本我是用Qt写的,在需要操作xml的地方直接调用tinyxml库进行写入或读取。 但昨天,老总给了我他写的对tinyxml的封装,意思是让我也对xml读取写入进行封装。然后我傻眼了,看了两天了,卡在将xml转成struct与将struct转回xml保存…… 配置文件xml在最下方: 其中IPCChannelParam子元素是搜索出来的,数量不定。 比如我定义的一个全局性的结构体: struct network_t { int DHCP; string IP; string MASK; }network_s; 怎样?有没有更好的定义方法啊? 求大神一定要帮忙啊,跪谢………………给个简单例子最好………… <?xml version="1.0" encoding="utf8"?> <decoder> <networkparam> <network> <interface DHCP="0"> <IP ipv4="192.168.1.123" /> <MASK ipv4="255.255.255.0" /> <GW ipv4="192.168.1.1" /> <HW a0="00" a1="11" a2="22" a3="123" a4="60" a5="32" /><!--MAC地址--> </interface> <DNS1 ipv4="111.210.230.111" /> <DNS2 ipv4="111.210.111.255" /> </network> </networkparam> <scheme mode="0" > <local> <IPCChannelParam> <Channel chanid="1" channame="192.168.1.149" used="1" ip="192.168.1.149" port="8091" protocol="0" netmode="0" username="admin" passwd="admin" /> <Channel chanid="2" channame="192.168.1.112" used="1" ip="192.168.1.112" port="8091" protocol="0" netmode="0" username="admin" passwd="admin" /> <Channel chanid="3" channame="192.168.1.157" used="1" ip="192.168.1.157" port="8091" protocol="0" netmode="0" username="admin" passwd="admin" /> <Channel chanid="4" channame="192.168.1.202" used="1" ip="192.168.1.202" port="8091" protocol="0" netmode="0" username="admin" passwd="admin" /> <Channel chanid="5" channame="192.168.1.151" used="1" ip="192.168.1.151" port="8091" protocol="0" netmode="0" username="admin" passwd="admin" /> <Channel chanid="6" channame="192.168.1.159" used="1" ip="192.168.1.159" port="8091" protocol="0" netmode="0" username="admin" passwd="admin" /> </IPCChannelParam> </local> </scheme> </decoder>
1 下一页