我很难找到一种方法来提取节点的所有属性的列表,而不知道它们被称为什么。
我正在使用以下方法提取单个已知属性:
xmlGetProp(cur, (const xmlChar*)"nodename")
但是如何使用 libxml2 获取所有属性的列表?
问候,马吕斯
只需遍历节点的属性列表,即:
xmlNodePtr Node = ...;
for(xmlAttrPtr attr = Node->properties; NULL != attr; attr = attr->next)
{
... do something with attr ...
... the name of the attribute is in attr->name ...
}
有趣的是,似乎没有一种方法可以做到这一点(虽然奇怪的是有 xmlFreePropList 函数),但是 xmlNode 结构有一个指向节点属性(属性)列表的指针。您可能可以获得指向该结构的指针。