读取文件以str方法读取:
- //设置文件路径
- string documentPath = CCFileUtils::sharedFileUtils()->getWriteablePath();
- string fileName = "test.xml";
- string filePath = documentPath + fileName;
- string path = filePath;
- //读怪文件内容,将文件以这符串的形式存入char中
- unsigned char* pBuffer = NULL;
- unsigned long bufferSize = 0;
- pBuffer = CCFileUtils::sharedFileUtils()->getFileData(path.c_str(), "r", &bufferSize);
用TiXmlDocument方式读取并解析:
- //用TiXmlDocument来解析XML
- TiXmlDocument *myDocument = new TiXmlDocument(path.c_str());
- myDocument->LoadFile();
- //获得根元素
- TiXmlElement *RootElement = myDocument->RootElement();
- //RootElement->Value()
- //获得节点。
- TiXmlElement *FirstPerson = RootElement->FirstChildElement();
- //获取节点属性
- TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
- //属性名称
- //IDAttribute->Name();
- //属性值
- //IDAttribute->Value();
这里给大家提供一下tinyXML下载,看附件!
转载于:https://blog.51cto.com/222355/1102275