Someone correct me if I'm wrong, I believe RapidXML will only give you values as some form of string due to its in-place parsing nature. The class templating might be for handling char vs wide char or something like that, I don't know, I only use char.
What I did to handle extracting values was to add a helper class to rapidxml_utils.hpp (could really have put it anywhere but it made sense there) with some static functions to parse a xml node or attribute to a value (or a default value if it doesn't parse).
These helpers have allowed me to do stuff like:
int Height = xml_helper::GetNodeInt(cur_node->first_node("Height"), 48);
int Width = xml_helper::GetNodeInt(cur_node->first_attribute("Width"), 128);
In your case you might use my helper class like this:
//Line which results in error (altered to use my helper class, if node absent or not parse as integer uses zero)
std::cout << xml_helper::GetNodeInt(node, 0)*10 << std::endl;
My helper class looks like this (I used sscanf to get some level of validation):
class xml_helper
{
public:
// a couple little helpers, lets you do this:
// int Height = xml_helper::GetNodeInt(cur_node->first_node("Height"), 48);
// int Width = xml_helper::GetNodeInt(cur_node->first_node("Width"), 128);
static int GetNodeInt(rapidxml::xml_base<>* node, int DefaultValue)
{
int temp;
try
{
if (node == 0) return DefaultValue;
if (sscanf(node->value(), "%d", &temp) != 1) return DefaultValue;
return temp;
//return atoi(node->value());
}
catch (...) { return DefaultValue; }
}
static unsigned int GetNodeUInt(rapidxml::xml_base<>* node, unsigned int DefaultValue)
{
unsigned int temp;
try
{
if (node == 0) return DefaultValue;
if (sscanf(node->value(), "%u", &temp) != 1) return DefaultValue;
return temp;
//return strtoul(node->value(), NULL, 0);
}
catch (...) { return DefaultValue; }
}
static long long GetNodeLL(rapidxml::xml_base<>* node, long long DefaultValue)
{
long long temp;
try
{
if (node == 0) return DefaultValue;
if (sscanf(node->value(), "%lld", &temp) != 1) return DefaultValue; //C99 covers %lld
return temp;
//return strtoll(node->value(), NULL, 0); //C++11, could use _strtoi64 in VS until then?
}
catch (...) { return DefaultValue; }
}
static double GetNodeDouble(rapidxml::xml_base<>* node, double DefaultValue)
{
double temp;
try
{
if (node == 0) return DefaultValue;
if (sscanf(node->value(), "%lf", &temp) != 1) return DefaultValue; // could use strtod
return temp;
}
catch (...) { return DefaultValue; }
}
static std::string GetNodeStr(rapidxml::xml_base<>* node, std::string DefaultValue)
{
try
{
if (node == 0) return DefaultValue;
return node->value();
}
catch (...) { return DefaultValue; }
}
};
Hopefully this may be helpful to you or someone else using rapidxml and needing a quick way to get integers, doubles, or whatever out of nodes. It can certainly be expanded to other types, I only have types I've needed so far in there now, but you get the gist of it.