我使用的是LIXML2和C++。以下函数在此处崩溃
return (char*)cur->content;
. 当我把它改成
return (char*)cur->name;
然后它就会回来
attribute
它是标签的名称。我想要的是1, 2,3(基于C++代码下面的XML文件)。我做错什么了?
char* xml2sdf::getId(xmlNode* part){
xmlNode* cur = part->xmlChildrenNode;
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;
}
}
}
它正在分析的XML文件部分:
<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>