In my XML file I have a node which is there per layer node like so:
<layer name="Tile Layer 1" width="30" height="30">
<data>
<tile gid="69"/>
<tile gid="69"/>
and
<layer name="Collsions" width="30" height="30">
<data>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
Now if I use the following statement using xpath
xmlChar *xpath = (xmlChar*) "//tile/@gid";
I can get all the tile gids. My issue is I would like to retrieve tile gids for just the collisions layer.
Some pseudo:
//get to layer node
if(name == collision)
{
get tile gids for this node list only
}
How do I do this?
I tried using the currentNode->xmlChildrenNode and it went down the nodes, but for some reason it returned “text” at one point? Is this due to whitespace?
I use this in the following code(expression changed to xmlChar *xpath = (xmlChar*) "/layer[@name=\"Collisions\"]/data/tile/@gid";
xmlChar *xpath = (xmlChar*) "/layer[@name=\"Collisions\"]/data/tile/@gid";//"//tile/@gid";
xmlNodeSetPtr nodeset;
xmlXPathObjectPtr result;
int i;
xmlChar *keyword;
int numCollisionTiles = 0;
result = getnodeset (doc, xpath);
if (result)
{
nodeset = result->nodesetval;
for (i=0; i < nodeset->nodeNr; i++)
{
keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
int id = atoi(keyword);
int index = i;
if(id == 111)
{
numCollisionTiles += 1;
index -= 899;
printf("tile id : %d for index: %d\n", id, index);
}
xmlFree(keyword);
}
xmlXPathFreeObject (result);
}
printf("number of collision tiles : %d\n", numCollisionTiles);
}
This code works when I use the following xmlChar *xpath = (xmlChar*) "//tile/@gid"
Could the following
keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
be causing xmlChar *xpath = (xmlChar*) "/layer[@name=\"Collisions\"]/data/tile/@gid"; to find nothing?
Try this:
/layer[@name="Collisions"]/data/title/@gidor
//tile[../../@name="Collisions"]/@gid