ref: 524f6890a72aa3629cc91ecf5c505ffa52f7eda4
dir: /libxml/xmlattr.c/
#include <u.h> #include <libc.h> #include "xml.h" Attr * xmlattr(Xml *xp, Attr **root, Elem *parent, char *name, char *value) { Attr *ap, *t; char *s; Ns *n; if((ap = xmlcalloc(xp, sizeof(Attr), 1)) == nil) sysfatal("no memory - %r\n"); if(*root == nil){ *root = ap; } else{ for (t = *root; t->next; t = t->next) continue; t->next = ap; } ap->parent = parent; if (name) { n = nil; if (strncmp(name, "xmlns:", 6) == 0) { n = xmlfindns(xp, name+6); } else if (strcmp(name, "xmlns") == 0) { n = xmlfindns(xp, nil); } if (n && value) n->decl = xmlstrdup(xp, value, 0); } if(name){ s = strchr(name, ':'); if (s) { ap->ns = xmlfindns(xp, name); s++; } else s = name; if((ap->name = xmlstrdup(xp, s, 1)) == nil) sysfatal("no memory - %r\n"); } if(value) if((ap->value = xmlstrdup(xp, value, 0)) == nil) sysfatal("no memory - %r\n"); return ap; }