RapidXML First node is null

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):

1
2
3
4
5
6
7
8
9
<level>
    <brick type="solid" num = "0">
        <position x="50" y="50" />       
    </brick>

    <brick type="not_solid" num = "1">
        <position x="100" y="100" />     
    </brick>
</level>


I'd like to add that it finds my xml file correctly (I've added an assert to make sure of this).

The code I'm using to try get the node looks like this:

 
xml_node<>* brickData = root->first_node("brick");


Does anyone have any idea where I could be going wrong? Any help is much appreciated!

Are you sure that you don't have a <xml> node around <level>, or a <!--Comment --> node at the top maybe?
Yes absolutely certain, the example above is the file in it's entirety at the moment.
Can we see the complete xml related code for this loading function ?
Here you go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
Topic archived. No new replies allowed.