I'm using libxml2 and C++. The following function crashes here at return (char*)cur->content;
. When I change it to return (char*)cur->name;
then it will return attribute
which is the name of the tag. What I want is 1, 2, and 3 (based on the XML file below the C++ code). What am I doing wrong?
char* xml2sdf::getId(xmlNode* part){
xmlNode* cur = part->xmlChildrenNode;
// get the id
while (cur != NULL) {
if ( !xmlStrcmp(cur->name, (const xmlChar *)"attribute") ) {
xmlAttrPtr attr = cur->properties;
if( !xmlStrcmp( attr->children->content, (const xmlChar*)"id" ) ){
return (char*)cur->content;
}
}
cur = cur->next;
}
}
}
The part of the XML file it is parsing:
<part ref="part10" name="part10">
<attribute name="face">7</attribute>
<attribute name="id">1</attribute>
</part>
<part ref="part20" name="part20">
<attribute name="face">5</attribute>
<attribute name="id">2</attribute>
</part>
<part ref="part30" name="part30">
<attribute name="face">9</attribute>
<attribute name="id">3</attribute>
</part>