c++ - 如何使用tinyxml2解析XML文件并将属性保存到结构体当中?
伊谢尔伦
伊谢尔伦 2017-04-17 13:10:56
0
1
745

我正在学习cocos2d-x游戏开发。
现在我需要从一个已有的XML文件中提取出精灵元素的相关信息,比如“名字”,“形状”,“颜色”等等。
我在代码中,声明了一个结构体,本意是用来存放提取出来的信息。
现在遇到的问题是,如何访问其中的属性标签并保存到结构体当中呢?
结构体代码如下:

typedef struct {
    std::string _color;
    std::string _shape;
    std::string _fileName;
}fishInfo;

xml文件结构如图:

请各位点拨一下。
或者发一下相关的xml解析完全指南之类的教程?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
洪涛

I don’t understand TinyXML, what the hell is that

pugi::xml_document doc;
doc.load_file('./file_name.xml');

pugi::xpath_node_set nodes = doc.select_nodes("/fishes/fish");
for(pugi::xpath_node_set::const_iterator iter = nodes.begin();
    iter != nodes.end(); ++iter) {
    pugi::xml_node node = iter->node();
    std::string color = node.attribute("color").as_string();
    std::string shape = node.attribute("shape").as_string();
    std::string name = node.attribute("name").as_string();
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!