Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4265320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:36:30+00:00 2026-05-21T06:36:30+00:00

In my XML file I have a node which is there per layer node

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:36:30+00:00Added an answer on May 21, 2026 at 6:36 am

    Try this:

    /layer[@name="Collisions"]/data/title/@gid

    or

    //tile[../../@name="Collisions"]/@gid

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I have an xml file that has an address node that looks like <address>
I have an xml file which looked something like this... <RootElementTag> <ChildElementTag1 attribute1=value1 />
I have an XML file which has a simple nodes like: <question lang='en'>Do you
I have an xml file which looks like the below example <Ids> <Id> <set>ai</set>
I have a XML file which has a node which is commented out. I
Say I have this given XML file: <root> <node>x</node> <node>y</node> <node>a</node> </root> And I
I would like to update an xml file from another xml file.I have used
I have a XML file like: <description> <text>blahblah</text> <code>code</code> <text>blah</text> </description> I've navigated to
I have an xml file in which i want to read the child nodes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.