/*! * \brief Returns a clone of an attribute node. * * \return A clone of an attribute node. */ static IXML_Attr *ixmlNode_cloneAttr( /*! [in] The \b Node to clone. */ IXML_Attr *nodeptr) { IXML_Attr *newAttr; IXML_Node *attrNode; IXML_Node *srcNode; int rc; assert(nodeptr != NULL); newAttr = (IXML_Attr *)malloc(sizeof (IXML_Attr)); if (newAttr == NULL) { return NULL; } ixmlAttr_init(newAttr); attrNode = (IXML_Node *)newAttr; srcNode = (IXML_Node *)nodeptr; rc = ixmlNode_setNodeName(attrNode, srcNode->nodeName); if (rc != IXML_SUCCESS) { ixmlAttr_free(newAttr); return NULL; } rc = ixmlNode_setNodeValue(attrNode, srcNode->nodeValue); if (rc != IXML_SUCCESS) { ixmlAttr_free(newAttr); return NULL; } /* Check to see whether we need to split prefix and localname for attribute */ rc = ixmlNode_setNamespaceURI(attrNode, srcNode->namespaceURI); if (rc != IXML_SUCCESS) { ixmlAttr_free(newAttr); return NULL; } rc = ixmlNode_setPrefix(attrNode, srcNode->prefix); if (rc != IXML_SUCCESS) { ixmlAttr_free(newAttr); return NULL; } rc = ixmlNode_setLocalName(attrNode, srcNode->localName); if (rc != IXML_SUCCESS) { ixmlAttr_free(newAttr); return NULL; } attrNode->nodeType = eATTRIBUTE_NODE; return newAttr; }
/*================================================================ * ixmlDocument_createAttributeEx * Creates an attribute of the given name. * External function. * Parameters: * name: The name of the Attribute node. * Return Value: * IXML_SUCCESS * IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. * ================================================================*/ int ixmlDocument_createAttributeEx( IN IXML_Document * doc, IN char *name, OUT IXML_Attr ** rtAttr ) { IXML_Attr *attrNode = NULL; int errCode = IXML_SUCCESS; attrNode = ( IXML_Attr * ) malloc( sizeof( IXML_Attr ) ); if( attrNode == NULL ) { errCode = IXML_INSUFFICIENT_MEMORY; goto ErrorHandler; } if( ( doc == NULL ) || ( name == NULL ) ) { ixmlAttr_free( attrNode ); attrNode = NULL; errCode = IXML_INVALID_PARAMETER; goto ErrorHandler; } ixmlAttr_init( attrNode ); attrNode->n.nodeType = eATTRIBUTE_NODE; /* set the node fields */ attrNode->n.nodeName = strdup( name ); if( attrNode->n.nodeName == NULL ) { ixmlAttr_free( attrNode ); attrNode = NULL; errCode = IXML_INSUFFICIENT_MEMORY; goto ErrorHandler; } attrNode->n.ownerDocument = doc; ErrorHandler: *rtAttr = attrNode; return errCode; }