| 32 | |
| 33 | #ifdef KEEP_COMPATABILITY |
| 34 | static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDocument **doc) |
| 35 | { |
| 36 | tinyxml2::XMLElement* curNode = NULL; |
| 37 | tinyxml2::XMLElement* rootNode = NULL; |
| 38 | |
| 39 | if (! CAUserDefault::isXMLFileExist()) |
| 40 | { |
| 41 | return NULL; |
| 42 | } |
| 43 | |
| 44 | // check the key value |
| 45 | if (! pKey) |
| 46 | { |
| 47 | return NULL; |
| 48 | } |
| 49 | |
| 50 | do |
| 51 | { |
| 52 | tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); |
| 53 | *doc = xmlDoc; |
| 54 | unsigned long nSize; |
| 55 | const char* pXmlBuffer = (const char*)CCFileUtils::sharedFileUtils()->getFileData(CAUserDefault::sharedUserDefault()->getXMLFilePath().c_str(), "rb", &nSize); |
| 56 | //const char* pXmlBuffer = (const char*)data.getBuffer(); |
| 57 | if(NULL == pXmlBuffer) |
| 58 | { |
| 59 | CCLOG("can not read xml file"); |
| 60 | break; |
| 61 | } |
| 62 | xmlDoc->Parse(pXmlBuffer); |
| 63 | delete[] pXmlBuffer; |
| 64 | // get root node |
| 65 | rootNode = xmlDoc->RootElement(); |
| 66 | if (NULL == rootNode) |
| 67 | { |
| 68 | CCLOG("read root node error"); |
| 69 | break; |
| 70 | } |
| 71 | // find the node |
| 72 | curNode = rootNode->FirstChildElement(); |
| 73 | if (!curNode) |
| 74 | { |
| 75 | // There is not xml node, delete xml file. |
| 76 | remove(CAUserDefault::sharedUserDefault()->getXMLFilePath().c_str()); |
| 77 | |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | while (NULL != curNode) |
| 82 | { |
| 83 | const char* nodeName = curNode->Value(); |
| 84 | if (!strcmp(nodeName, pKey)) |
| 85 | { |
| 86 | // delete the node |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | curNode = curNode->NextSiblingElement(); |
| 91 | } |
no test coverage detected