zoukankan      html  css  js  c++  java
  • 学习笔记之cocos2dx2.1.1实现修改plist文件数据,用TinyXml解析XML

    如果不了解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");  
    	}


  • 相关阅读:
    调试常用命令
    android获取手机机型、厂商、deviceID基本信息
    融云即时通讯 添加地理位置信息的功能
    Linux centOS下搭建RTMP服务器的具体步骤
    数组与字符串 1.4
    数组与字符串 1.5
    数组与字符串 1.3
    数组与字符串 1.2
    数组与字符串 1.1
    笔记本自开wifi设置
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/2990573.html
Copyright © 2011-2022 走看看