Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get attributes from a node in libxml2

Tags:

c

libxml2

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 to get the count of the attributes.

like image 843
kiri Avatar asked Jul 07 '09 13:07

kiri


1 Answers

I think joostk meant attribute->children, giving something like this:

xmlAttr* attribute = node->properties;
while(attribute)
{
  xmlChar* value = xmlNodeListGetString(node->doc, attribute->children, 1);
  //do something with value
  xmlFree(value); 
  attribute = attribute->next;
}

See if that works for you.

like image 79
Matthew Lowe Avatar answered Sep 22 '22 04:09

Matthew Lowe