ref: 47a288683dbdc55c5df9b9f65db9909de6021af0
dir: /libxml/xmlelem.c/
#include <u.h>
#include <libc.h>
#include "xml.h"
Elem *
xmlelem(Xml *xp, Elem **root, Elem *parent, char *name)
{
Elem *ep, *t;
Ns *ns;
char *s;
USED(xp);
if((ep = xmlcalloc(xp, sizeof(Elem), 1)) == nil)
sysfatal("no memory - %r\n");
if(! *root){
*root = ep;
}
else{
for (t = *root; t->next; t = t->next)
continue;
t->next = ep;
}
ns = strchr(name, ':') ? xmlfindns(xp, name) : xmlfindns(xp, nil);
ep->ns = ns;
ep->parent = parent;
if(name){
s = strchr(name, ':');
if (s)
s++;
else
s = name;
if((ep->name = xmlstrdup(xp, s, 1)) == nil)
sysfatal("no memory - %r\n");
}
return ep;
}