TinyXML parsing XML string returns NULL?

I am trying to use TinyXML to parse a string in XML format. But the return pointer is always NULL. I am not sure which part of the code is 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!

+3
source share
4 answers

Parse seems to return null if successful.

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

+1
source

0 , , TiXmlBase:: SkipWhiteSpace , , 0, \r \n . , 2 , SkipWhiteSpace:

if ( !p || !*p )
{
    return 0;
}

- :

if ( !p )
{
   return 0;
}
if (!*p)
{
   return p;
}
+4
 if(pTest == NULL && docTemp->Error() ){
        cout << "pTest is NULL" << endl;
    }
+3
source

It looks like it TiXMLDocument::Parsereturns NULLin the event of a failure and the pointer to the character next to the closing angle bracket when the parsing was successful.

+1
source

All Articles