MCPcopy Create free account
hub / github.com/9miao/CrossApp / getXMLNodeForKey

Function getXMLNodeForKey

CrossApp/support/user_default/CAUserDefaultAndroid.cpp:34–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32
33#ifdef KEEP_COMPATABILITY
34static 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 }

Callers 11

deleteNodeByKeyFunction · 0.85
getBoolForKeyMethod · 0.85
getIntegerForKeyMethod · 0.85
getFloatForKeyMethod · 0.85
getDoubleForKeyMethod · 0.85
getStringForKeyMethod · 0.85
setValueForKeyFunction · 0.85
getBoolForKeyMethod · 0.85
getIntegerForKeyMethod · 0.85
getDoubleForKeyMethod · 0.85
getStringForKeyMethod · 0.85

Calls 7

ParseMethod · 0.80
FirstChildElementMethod · 0.80
ValueMethod · 0.80
NextSiblingElementMethod · 0.80
removeFunction · 0.50
getFileDataMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected