views:

50

answers:

1
const XMLDataNode *pointsNode = node->GetChildren().at(0);
std::wistringstream pointsstrm(*pointsNode->GetInnerText());
pointsstrm >> loadedGame.points;

This is code I've written to pull an int from an XML file and pass it into loadedGame.points (an int). However, this isn't working. It compiles but doens't give the right value. Why is that? XMLDataNode is a class that manipulates xmllite.dll.

A: 

Time for some wild guesses!

I'll bet you that the text you get from *pointsNode->GetInnerText() isn't what you think it is. Have you checked that it is indeed exactly the text you want? In particular, could it contain whitespace? Parsing a nicely formatted (i.e. indented, broken into lines, etc) XML file without a schema to reference ends up meaning that all sorts text nodes involving whitespace will end up in your DOM tree.

Managu
Though of course, my std::wistringstream (GNU libstdc++6) seems to ignore whitespace when extracting an integer. There's still a valid concern -- are you sure that what's returned by `*pointsNode->getInnerText()` is what you expect it to be? A debug print statement might be quite handy here.
Managu