static int node_rm_attr(lua_State *L) { xmlNodePtr node = lua_touserdata(L, 1); const char *name = lua_tostring(L, 2); const char *ns_str = lua_tostring(L, 3); xmlNsPtr ns = NULL; int ret; if (node == NULL) return luaL_error(L, "rm_attribute: Invalid node"); if (node->type != XML_ELEMENT_NODE) return luaL_error(L, "rm_attribute: Invalid node type (not element node)"); if (name == NULL) return luaL_error(L, "rm_attribute: Specify attribute name"); if (ns_str != NULL) { ns = xmlSearchNsByHref(node->doc, node, BAD_CAST ns_str); if (ns == NULL) return luaL_error(L, "Namespace not defined yet."); } if (ns == NULL) { ret = xmlUnsetProp(node, BAD_CAST name); } else { ret = xmlUnsetNsProp(node, ns, BAD_CAST name); } /** * Boolean variable indicates TRUE as 1 and FALSE as 0 * xmlUnset*Prop returns O for OK and -1 for error * 0(ok) + 1 = 1(true) and -1(error) + 1 = 0(false) */ lua_pushboolean(L, ret+1); return 1; }
// void removeAttributeNS(in DOMString namespaceURI, in DOMString localName) raises(DOMException); static void _removeAttributeNS(Request& r, MethodParams& params) { const xmlChar* namespaceURI=as_xmlnsuri(r, params, 0); const xmlChar* localName=as_xmlname(r, params, 1); VXnode& vnode=GET_SELF(r, VXnode); xmlNode& element=get_self_element(vnode); VXdoc& vxdoc=vnode.get_vxdoc(); xmlDoc& xmldoc=vxdoc.get_xmldoc(); // @todo: when name="xmlns" xmlNs& ns=pa_xmlMapNs(xmldoc, namespaceURI, 0); xmlUnsetNsProp(&element, &ns, localName); }