记录一些TinyXml使用指南(3)
2006-08-01 13:10
267 查看
#include <iostream> #include <fstream> #include "tinyxml.h" using namespace std; int main() { string filename = "first.xml"; TiXmlDocument* doc = new TiXmlDocument(filename.c_str()); ////////////////////////////////////////////////////////////////////////// // 在这里复制文件 ////////////////////////////////////////////////////////////////////////// std::ifstream ifs(filename.c_str()); char buffer[1024]; char c, *p = buffer; while(ifs.get(c)) { *p++=c; } *p = 0; ifs.close(); ////////////////////////////////////////////////////////////////////////// if(!doc->Parse(buffer)) { cout << doc->ErrorDesc() << endl; } const TiXmlElement* root = doc->RootElement(); for( const TiXmlNode* child = root->FirstChild(); child; child=child->NextSibling()) { OutputDebugStringA(child->Value()); /* 生成一个StaticBox <staticbox mesh="crate.mesh"> <position x="-8" y="2" z="4" /> <dimension x="2" y="4" z="2" /> </staticbox> */ if((child->Type() == TiXmlNode::ELEMENT) && (!strcmp(child->Value(),"staticbox"))) { const TiXmlElement *box = (const TiXmlElement*)child; double px, py, pz; double dx, dy, dz; std::string mesh; mesh = box->Attribute("mesh"); for(const TiXmlNode *sub_tag = box->FirstChild(); sub_tag; sub_tag = sub_tag->NextSibling() ) { if(sub_tag->Type() == TiXmlNode::ELEMENT) { const TiXmlElement *sub_element = (const TiXmlElement*)sub_tag; if(!strcmp(sub_tag->Value(),"position")) { px = (sub_element->Attribute("x",&px))?px:0.0; py = (sub_element->Attribute("y",&py))?py:0.0; pz = (sub_element->Attribute("z",&pz))?pz:0.0; } else if(!strcmp(sub_tag->Value(),"dimension")) { dx = (sub_element->Attribute("x",&dx))?dx:1.0; dy = (sub_element->Attribute("y",&dy))?dy:1.0; dz = (sub_element->Attribute("z",&dz))?dz:1.0; } } } cout << "<StaticBox>/n"; cout << "/tPosition = (" << px << ", " << py << ", " << pz << ")/n"; cout << "/tDimension = (" << dx << ", " << dy << ", " << dz << ")/n/n"; } } delete doc; getchar(); return 0; } |
<?xml version="1.0" encoding="utf-8" ?> <Scene> <staticbox mesh="crate.mesh"> <position x="-8" y="2" z="4" /> <dimension x="2" y="4" z="2" /> </staticbox> <staticbox mesh="crate.mesh"> <position x="3" y="2" z="4" /> <dimension x="2" y="4" z="2" /> </staticbox> </Scene> |
相关文章推荐
- 记录一些TinyXml使用指南(1)
- 记录一些TinyXml使用指南(2)
- 记录一些TinyXml使用指南(4)
- 这里将记录一些我用过的,经常想不起来的东西
- 关于NFC芯片选择的一些记录
- Android应用测试工具使用的一些心得记录
- 记录一些数据库函数或全局变量
- canvas的一些问题记录
- 关于一些有意思的控件属性记录
- 关于Vue的一些小用法(记录)
- Linux一些初始化设置记录
- 最近安装了SQL Server2008 R2 64位的数据库,出现了一些问题,记录如下
- 直播技术总结(三)ijkplayer的一些问题优化记录
- 记录一些Java操作OpenXML的方式
- 关于SDIO接口的wifi和通用SD卡的一些记录
- TinyXML是的一些简单说明与用法
- 使用Spring MVC3和Hibernate4做网站的一些记录
- 一些小问题记录
- Jquery事件绑定的一些记录
- 记录一些有用的内容。