1
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.

1 Answer 1

6
if (pElem && pElem->GetText())
    StatusResponse = pElem->GetText();
Sign up to request clarification or add additional context in comments.

2 Comments

How painfully obvious. Thank you very much.
I would store the return value of GetText() to a local variable to avoid calling GetText() twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.