|
XMLAPI XML * xml_insertbefore (XML * orig, XML * new)
{
ELEMENTLIST * list;
ELEMENTLIST * ch;
if (orig == NULL) return new;
if (orig->parent == NULL) return new;
if (new == NULL) return new;
list = orig->parent->children;
while (list != NULL && list->element != orig) list = list->next;
if (list == NULL) return new;
new->parent = orig->parent;
ch = (ELEMENTLIST *) MALLOC (sizeof(struct _list));
ch->element = new;
ch->next = list;
ch->prev = list->prev;
if (!ch->prev) orig->parent->children = ch;
else ch->prev->next = ch;
list->prev = ch;
return (new);
}
XMLAPI XML * xml_insertafter (XML * orig, XML * new)
{
ELEMENTLIST * list;
ELEMENTLIST * ch;
if (orig == NULL) return new;
if (orig->parent == NULL) return new;
if (new == NULL) return new;
list = orig->parent->children;
while (list != NULL && list->element != orig) list = list->next;
if (list == NULL) return new;
new->parent = orig->parent;
ch = (ELEMENTLIST *) MALLOC (sizeof(struct _list));
ch->element = new;
ch->prev = list;
ch->next = list->next;
if (!ch->next) orig->parent->lastchild = ch;
else ch->next->prev = ch;
list->next = ch;
return (new);
}
|