How to get attributes from a node in libxml2

前端 未结 6 2071
孤街浪徒
孤街浪徒 2020-12-20 18:32

I am working on a parser to get data from an XML file. I am using libxml2 to extract data. I am a not able to get the attributes from nodes. I only found nb_attributes

6条回答
  •  我在风中等你
    2020-12-20 19:25

    Try something like:

    xmlNodePtr node; // Some node
    NSMutableArray *attributes = [NSMutableArray array];
    
    for(xmlAttrPtr attribute = node->properties; attribute != NULL; attribute = attribute->next){
        xmlChar *content = xmlNodeListGetString(node->doc, attribute->children, YES);
        [attributes addObject:[NSString stringWithUTF8String:content]];
        xmlFree(content);
    }
    

提交回复
热议问题