如果不了解TinyXml,建议先看一下这篇博客
http://blog.csdn.net/nat_myron/article/details/8740028
plist文件如下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>picture</key>
<array>
<string>1.png</string>
<string>2.png</string>
<string>3.png</string>
</array>
<key>point</key>
<array>
<string>{257.902405,410.831543}</string>
<string>{521.964294,436.794006}</string>
<string>{766.067932,410.830719}</string>
</array>
</dict>
</plist>
操作如下
TiXmlDocument *myDocument = new TiXmlDocument("SmallTools.plist");
myDocument->LoadFile();
TiXmlElement *RootPlist = myDocument->RootElement();//plist
TiXmlElement *FirstDict = RootPlist->FirstChildElement();//dict
TiXmlElement *FirstKey = FirstDict->FirstChildElement();//key
TiXmlElement *SecDict = FirstKey->NextSiblingElement();//array
TiXmlElement *SecKey = SecDict->NextSiblingElement();//key
TiXmlElement *ThirdDict = SecKey->NextSiblingElement();//array
CCLOG(ThirdDict->Value());
//删除所有的子结点
ThirdDict->Clear();
for (int i=0;i<TagCount;i++)
{
CCSprite* sprite = (CCSprite*)sprite_array->objectAtIndex(i);
CCPoint point = sprite->getPosition();
char str[50];
sprintf(str,"{%lf,%lf}",point.x,point.y);
TiXmlElement *NameElement = new TiXmlElement("string");
ThirdDict->LinkEndChild(NameElement);
TiXmlText *NameContent = new TiXmlText(str);
NameElement->LinkEndChild(NameContent);
myDocument->SaveFile("SmallTools.plist");
}
包含头文件
#include "tinystr.h"
#include "tinyxml.h"