1 CCParticleSystem.cpp 2 m_sPlistFile = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(plistFile); 3 CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(m_sPlistFile.c_str()); 4 5 CCDictionary.cpp 6 CCDictionary* CCDictionary::createWithContentsOfFileThreadSafe(const char *pFileName) 7 { 8 return ccFileUtils_dictionaryWithContentsOfFileThreadSafe(pFileName); 9 } 10 11 CCFileUtilsCommon_cpp.h 12 CCDictionary* ccFileUtils_dictionaryWithContentsOfFileThreadSafe(const char *pFileName) 13 { 14 CCDictMaker tMaker; 15 return tMaker.dictionaryWithContentsOfFile(pFileName); 16 } 17 18 CCFileUtilsCommon_cpp.h 19 CCDictionary* dictionaryWithContentsOfFile(const char *pFileName) 20 { 21 m_eResultType = SAX_RESULT_DICT; 22 CCSAXParser parser; 23 24 if (false == parser.init("UTF-8")) 25 { 26 return NULL; 27 } 28 parser.setDelegator(this); 29 30 parser.parse(pFileName); 31 return m_pRootDict; 32 } 33 34 35 bool CCSAXParser::parse(const char *pszFile) 36 { 37 bool bRet = false; 38 unsigned long size = 0; 39 char* pBuffer = (char*)CCFileUtils::sharedFileUtils()->getFileData(pszFile, "rt", &size); 40 if (pBuffer != NULL && size > 0) 41 { 42 bRet = parse(pBuffer, size); 43 } 44 CC_SAFE_DELETE_ARRAY(pBuffer); 45 return bRet; 46 } 47 48 49 bool CCSAXParser::parse(const char* pXMLData, unsigned int uDataLength) 50 { 51 /* 52 * this initialize the library and check potential ABI mismatches 53 * between the version it was compiled for and the actual shared 54 * library used. 55 */ 56 LIBXML_TEST_VERSION 57 xmlSAXHandler saxHandler; 58 memset( &saxHandler, 0, sizeof(saxHandler) ); 59 // Using xmlSAXVersion( &saxHandler, 2 ) generate crash as it sets plenty of other pointers... 60 saxHandler.initialized = XML_SAX2_MAGIC; // so we do this to force parsing as SAX2. 61 saxHandler.startElement = &CCSAXParser::startElement; 62 saxHandler.endElement = &CCSAXParser::endElement; 63 saxHandler.characters = &CCSAXParser::textHandler; 64 65 int result = xmlSAXUserParseMemory( &saxHandler, this, pXMLData, uDataLength ); 66 if ( result != 0 ) 67 { 68 return false; 69 } 70 /* 71 * Cleanup function for the XML library. 72 */ 73 xmlCleanupParser(); 74 /* 75 * this is to debug memory for regression tests 76 */ 77 #if (CC_TARGET_PLATFORM != CC_PLATFORM_BADA) 78 xmlMemoryDump(); 79 #endif 80 81 return true; 82 }
<?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>angle</key> <real>270</real> <key>angleVariance</key> <real>0.0</real> ...... </dict> </plist>
1 //创建test.plist文件 2 m_Writer = xmlNewTextWriterFilename(plist, 0); 3 4 //设置编码为utf-8并开始文档 5 xmlTextWriterStartDocument(m_Writer, NULL, "UTF-8", NULL); 6 //设置文档类型 7 xmlTextWriterWriteDTD(m_Writer, BAD_CAST "plist", BAD_CAST "-//Apple//DTD PLIST 1.0//EN", BAD_CAST "http://www.apple.com/DTDs/PropertyList-1.0.dtd", NULL); 8 //根节点为plist,version属性为1.0 9 xmlTextWriterStartElement(m_Writer, BAD_CAST "plist"); 10 xmlTextWriterWriteAttribute(m_Writer, BAD_CAST "version", BAD_CAST "1.0"); 11 12 //dict节点 13 xmlTextWriterStartElement(m_Writer, BAD_CAST "dict"); 14 15 //写入测试数据 16 xmlTextWriterWriteElement(m_Writer, BAD_CAST "key", BAD_CAST "key1"); 17 xmlTextWriterWriteElement(m_Writer, BAD_CAST "real", BAD_CAST "key1"); 18 19 //写入Base64数据 20 xmlTextWriterStartElement(m_Writer, BAD_CAST "Texture"); 21 xmlTextWriterWriteBase64(m_Writer, "abcdefghij", 0, 12); 22 xmlTextWriterEndElement(m_Writer); 23 24 //结束并保存 25 xmlTextWriterEndDocument(m_Writer);