Search code examples
c++libxml2collada

Collada loading with libxml2


I want to load collada with libxml2. I get the COLLOADA node, okay, then I try to get the children tag - FAIL, the children tag name is "text". Why? How can i get the child of COLLADA node?

xmlNode* geometries = xmlDocGetRootElement(doc)->children;

//at THIS point the geometries->name == "text"  WHY?
//IS not it supposed to be "asset"?

while(!xmlStrcmp(geometries->name, (const xmlChar*)"library_geometries")) 
geometries = geometries->next;


xmlNode* mesh = geometries->children;
for(uint i = 0; i < idx; i++)
mesh = mesh->next;

Where am I wrong?


Solution

  • Take a look at this method from this example in the libxml2 website:

    static void
    print_element_names(xmlNode * a_node)
    {
        xmlNode *cur_node = NULL;
    
        for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
            if (cur_node->type == XML_ELEMENT_NODE) {
                printf("node type: Element, name: %s\n", cur_node->name);
            }
        }
    
        print_element_names(cur_node->children);
    }
    

    Notice that this code checks if a node is of type XML_ELEMENT_NODE before printing its name. The "text" node that you are reading is the text between the opening and closing tags:

    <myTag>This is the text between the tags</myTag>