Search code examples
tinyxml

TinyXML parsing a string in XML format returns NULL?


I'm trying to use TinyXML to parse a string with XML format. But the return pointer is always NULL. I'm not sure which part of code is setting wrong.

TiXmlDocument docTemp;
const string strData = "<?xml version=\"1.0\" ?><Hello>World</Hello>";
const char* pTest = docTemp.Parse(strData.c_str(), 0 , TIXML_ENCODING_UTF8);
if(pTest == NULL){
    cout << "pTest is NULL" << endl;
}

It always shows 'pTest is NULL' Any idea?

Thanks a bunch!


Solution

  • It seems like the parse returns null on success.

    Can you see if docTemp.RootElement() contains a valid element ?