Smurf64
Smurf64

Reputation: 337

How to handle tinyxml null pointer returned on GetText()

TiXmlElement *pElem;    
std::string StatusResponse;
pElem = hResponse.FirstChild("StatusResponse").Element();

if (pElem)
    StatusResponse = pElem->GetText();

If pElem is valid but the element contains no text, pElem->GetText() returns a NULL pointer, causing an exception. How should I handle this?

Thanks.

Upvotes: 1

Views: 2881

Answers (1)

James McNellis
James McNellis

Reputation: 355207

if (pElem && pElem->GetText())
    StatusResponse = pElem->GetText();

Upvotes: 6

Related Questions