Hey there, I'm busy implementing RapidXML as a resource manager for my game engine. I'm running into a problem that it cannot find the first node within the XML file which it needs in order to iterate through them all.
Does anyone have any experience implementing this? What could the issue be? The XML is pretty simple and looks like this (at the moment):
void LoadXML(std::string fileName)
{
//Load file.
std::ifstream inFile(fileName.c_str());
assert(inFile);
std::string xmlContents;
std::vector<char> xmlData = std::vector<char>(xmlContents.begin(), xmlContents.end());
xmlData.push_back('\0');
xml_document<> doc;
doc.parse<parse_no_data_nodes>(&xmlData[0]);
//Get our root node.
xml_node<>* root = doc.first_node();
//Some variables used in the following code.
std::string brickType;
int brickNum;
//Parse brick nodes.
xml_node<>* brickData = root->first_node("brick");
while(brickData)
{
//Get the image file we're parsing and load it
brickType = brickData->first_attribute("type")->value();
brickNum = atoi(brickData->first_attribute("num")->value());
loadedBricks.push_back(new Brick());
loadedBricks[brickNum]->SetBrick(brickType);
//Go through each tile
xml_node<>* position = brickData->first_node("position");
while(position)
{
//Get X & Y attributes.
int x = atoi(position->first_attribute("x")->value());
int y = atoi(position->first_attribute("y")->value());
loadedBricks[brickNum]->SetPosition(x, y);
//Go to the position. Not needed since we only have one.
//position = position->next_sibling();
}
//Go to the next brick.
brickData = brickData->next_sibling();
}
}
Hmm, i don't know how rapidXML works, but maybe you should load inFile content into xmlContents before parsing it.
PS : please note that the General C++ section of this forum is meant for the C++ language itself related problems. Library specific problems should be asked on the library provider's website