* xmlSetNsProp: * @node: the node * @ns: the namespace definition * @name: the attribute name * @value: the attribute value * * Set (or reset) an attribute carried by a node. * The ns structure must be in scope, this is not checked * * Returns the attribute pointer. */
| 6967 | * Returns the attribute pointer. |
| 6968 | */ |
| 6969 | xmlAttrPtr |
| 6970 | xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, |
| 6971 | const xmlChar *value) |
| 6972 | { |
| 6973 | xmlAttrPtr prop; |
| 6974 | |
| 6975 | if (ns && (ns->href == NULL)) |
| 6976 | return(NULL); |
| 6977 | if (name == NULL) |
| 6978 | return(NULL); |
| 6979 | prop = xmlGetPropNodeInternal(node, name, |
| 6980 | (ns != NULL) ? ns->href : NULL, 0); |
| 6981 | if (prop != NULL) { |
| 6982 | xmlNodePtr children = NULL; |
| 6983 | |
| 6984 | /* |
| 6985 | * Modify the attribute's value. |
| 6986 | */ |
| 6987 | if (value != NULL) { |
| 6988 | children = xmlNewDocText(node->doc, value); |
| 6989 | if (children == NULL) |
| 6990 | return(NULL); |
| 6991 | } |
| 6992 | |
| 6993 | if (prop->atype == XML_ATTRIBUTE_ID) { |
| 6994 | xmlRemoveID(node->doc, prop); |
| 6995 | prop->atype = XML_ATTRIBUTE_ID; |
| 6996 | } |
| 6997 | if (prop->children != NULL) |
| 6998 | xmlFreeNodeList(prop->children); |
| 6999 | prop->children = NULL; |
| 7000 | prop->last = NULL; |
| 7001 | prop->ns = ns; |
| 7002 | if (value != NULL) { |
| 7003 | xmlNodePtr tmp; |
| 7004 | |
| 7005 | prop->children = children; |
| 7006 | prop->last = NULL; |
| 7007 | tmp = prop->children; |
| 7008 | while (tmp != NULL) { |
| 7009 | tmp->parent = (xmlNodePtr) prop; |
| 7010 | if (tmp->next == NULL) |
| 7011 | prop->last = tmp; |
| 7012 | tmp = tmp->next; |
| 7013 | } |
| 7014 | } |
| 7015 | if ((prop->atype == XML_ATTRIBUTE_ID) && |
| 7016 | (xmlAddIDSafe(prop, value) < 0)) { |
| 7017 | return(NULL); |
| 7018 | } |
| 7019 | return(prop); |
| 7020 | } |
| 7021 | /* |
| 7022 | * No equal attr found; create a new one. |
| 7023 | */ |
| 7024 | return(xmlNewPropInternal(node, ns, name, value, 0)); |
| 7025 | } |
| 7026 |
no test coverage detected