michaelrsweet / mxml

Tiny XML library.
https://www.msweet.org/mxml
Apache License 2.0
428 stars 157 forks source link

Iterate attributes and get their names #249

Closed Opariti closed 5 years ago

Opariti commented 5 years ago

Hi, I used to get, in version 2.11 the names AND values fo a node's attributes. In v.3 I have only the possibility to iterate and get the attributes' values, but not their name. How could I solve this (getting node's both attribute's name and value, by index)? Thanks

michaelrsweet commented 5 years ago

Use mxmlElementGetAttrCount and mxmlElementGetAttrByIndex, e.g.:

mxml_node_t *element;
int i, count;
const char *name, *value;

for (i = 0, count = mxmlElementGetAttrCount(element); i < count; i ++)
{
  value = mxmlElementGetAttrByIndex(element, i, &name);
  printf("%s=\"%s\"\n", name, value);
}

Those functions were added in Mini-XML v2.11...

Opariti commented 5 years ago

Many thanks Michael!