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!
Parse seems to return null if successful.
Do you see if docTemp.RootElement () contains a valid element?
0 , , TiXmlBase:: SkipWhiteSpace , , 0, \r \n . , 2 , SkipWhiteSpace:
if ( !p || !*p ) { return 0; }
- :
if ( !p ) { return 0; } if (!*p) { return p; }
if(pTest == NULL && docTemp->Error() ){ cout << "pTest is NULL" << endl; }
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.
TiXMLDocument::Parse
NULL