Skip to content

Instantly share code, notes, and snippets.

@mahdavipanah
Last active January 4, 2018 01:15
Show Gist options
  • Save mahdavipanah/f3886ddb4e31c254c064db5b67823319 to your computer and use it in GitHub Desktop.
Save mahdavipanah/f3886ddb4e31c254c064db5b67823319 to your computer and use it in GitHub Desktop.
XML in C - Golbarg
xattribute_t* add_xattribute(xelement_t* e, const char* name, const char* value){
// either element already has some attributes or not
// in both situations we have to create a new attribute to add
// we call it "atr" and first we initate it
xattribute_t* atr = (xattribute_t*)malloc(sizeof(xattribute_t));
atr->name = strdup(name);
atr->value = strdup(value);
atr->next = NULL;
// Now we check if element has no attribute
if (e->listatt == NULL) {
e->listatt=atr;
}
// but if element already has some attributes, we add the new attribute
// at the end of it's attribute list
else {
xattribute_t* temp = e->listatt;
// go until reaching the last attribute
while(temp->next != NULL){
temp = temp->next;
}
temp->next = atr;
}
// then we return the newly added attribute
return atr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment