Logo Search packages:      
Sourcecode: libupnp4 version File versions  Download package

EXPORT_SPEC int ixmlElement_setAttributeNode ( IXML_Element element,
IXML_Attr newAttr,
IXML_Attr **  rtAttr 
)

Adds a new attribute node to an Element.

If an attribute already exists with newAttr as a name, it will be replaced with the new one and the old one will be returned in rtAttr.

Returns:
If successfull, the replaced attribute node is returned in rtAttr, otherwise, NULL is returned in this pointer. The function return value is an integer representing one of the following:
  • IXML_SUCCESS: The operation completed successfully.
  • IXML_INVALID_PARAMETER: Either element or newAttr is NULL.
  • IXML_WRONG_DOCUMENT_ERR: newAttr does not belong to the same one as element.
  • IXML_INUSE_ATTRIBUTE_ERR: newAttr is already an attribute of another Element.
Parameters:
element  [in] The Element in which to add the new attribute.
newAttr  [in] The new Attr to add.
rtAttr  [out] A pointer to an Attr where the old Attr will be stored. This will have a NULL if no prior node existed.

Definition at line 222 of file element.c.

References _IXML_Node::firstAttr, _IXML_Element::n, _IXML_ATTR::n, _IXML_Node::nextSibling, _IXML_Node::nodeName, _IXML_Node::ownerDocument, _IXML_ATTR::ownerElement, and _IXML_Node::prevSibling.

Referenced by ixmlElement_setAttribute(), and Parser_processAttributeName().

{
      IXML_Node *attrNode = NULL;
      IXML_Node *node = NULL;
      IXML_Node *nextAttr = NULL;
      IXML_Node *prevAttr = NULL;
      IXML_Node *preSib = NULL;
      IXML_Node *nextSib = NULL;

      if (element == NULL || newAttr == NULL) {
            return IXML_INVALID_PARAMETER;
      }

      if (newAttr->n.ownerDocument != element->n.ownerDocument) {
            return IXML_WRONG_DOCUMENT_ERR;
      }

      if (newAttr->ownerElement != NULL) {
            return IXML_INUSE_ATTRIBUTE_ERR;
      }

      newAttr->ownerElement = element;
      node = (IXML_Node *)newAttr;

      attrNode = element->n.firstAttr;
      while (attrNode != NULL) {
            if (strcmp(attrNode->nodeName, node->nodeName) == 0) {
                  /* Found it */
                  break;
            } else {
                  attrNode = attrNode->nextSibling;
            }
      }

      if (attrNode != NULL) {
            /* Already present, will replace by newAttr */
            preSib = attrNode->prevSibling;
            nextSib = attrNode->nextSibling;
            if (preSib != NULL) {
                  preSib->nextSibling = node;
            }
            if (nextSib != NULL) {
                  nextSib->prevSibling = node;
            }
            if (element->n.firstAttr == attrNode) {
                  element->n.firstAttr = node;
            }
            if (rtAttr != NULL) {
                  *rtAttr = (IXML_Attr *)attrNode;
            }
      } else {
            /* Add this attribute */
            if (element->n.firstAttr != NULL) {
                  prevAttr = element->n.firstAttr;
                  nextAttr = prevAttr->nextSibling;
                  while (nextAttr != NULL) {
                        prevAttr = nextAttr;
                        nextAttr = prevAttr->nextSibling;
                  }
                  prevAttr->nextSibling = node;
                  node->prevSibling = prevAttr;
            } else {
                  /* This is the first attribute node */
                  element->n.firstAttr = node;
                  node->prevSibling = NULL;
                  node->nextSibling = NULL;
            }

            if (rtAttr != NULL) {
                  *rtAttr = NULL;
            }
      }

      return IXML_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index