Program with read xml in cocos2d-x 3.0

Hi everybody !

I have a problem when upgrade to cocos2d-x 3.0.

This is my XmlReader class and my string.xml

EGXMLReader.h

class EGXMLReader {
private:
	CCDictionary* m_dictionary;
public:
	EGXMLReader(const char* dicFilename);
	~EGXMLReader();
	const char* GetStringByKey(const char* keyword);
	static const char* GetStringByKeyFromFile(const char* dicFilename, const char* keyword);
};

EGXMLReader.cpp

EGXMLReader::EGXMLReader(const char* dicFilename) {
	this->m_dictionary = CCDictionary::createWithContentsOfFile(dicFilename);
}

EGXMLReader::~EGXMLReader() {
}

const char* EGXMLReader::GetStringByKey(const char* keyword) {
	return ((CCString*)(this->m_dictionary->objectForKey(keyword)))->getCString();
}

const char* EGXMLReader::GetStringByKeyFromFile(const char* dicFilename, const char* keyword) {
	CCDictionary *dictionary = CCDictionary::createWithContentsOfFile(dicFilename);
	return ((CCString*)dictionary->objectForKey(keyword))->getCString();
}

string.xml

abc // If like this it’s report Assert failed: key not found : <integer/real>
abcabc // else it’s report this dictionary does not use string as key.

Someone help me. I don’t know what i wrong :frowning:

Hi,
<string key="abc">abc</string> is not the standard plist format. So we don’t support it.
<key>abc</key><string>abc</string is supported. I tested it. And I did read the value of abc key.
BTW, CCDictionary was deprecated from v3.0. You could use FileUtils::getInstance()->getValueMapFromFile(filename) instead.
It will return a ValueMap which is a typedef of std::unordered_map<std::string, Value>.
To get a value for a key, you could use valuemap.at("key_name").