/*RemoveAttribute - remove attribute from element attname - name of attribute to remove returns False on error */ Bool CXMLElement::RemoveAttribute(char *attname) { if (!isinited()) return False; // OK-2009-01-06: [[Bug 7586]] - Remove the namespace if that is the name of the attribute. // Not sure how reliable this is, it seems to work ok. The revXMLRemoveAttribute is not currently // documented. if (strcasecmp(attname, "xmlns") == 0) { xmlNsPtr t_namespace; t_namespace = NULL; GetNamespace(t_namespace); if (t_namespace != NULL) xmlFreeNs(t_namespace); element -> ns = NULL; element -> nsDef = NULL; return True; } else { int res = xmlUnsetProp (element, (xmlChar *)attname); return res == 0; } }
static int noit_config_check_update_attrs(xmlNodePtr node, int argc, char **argv) { int i, error = 0; if(argc % 2) return -1; for(i=0; i<argc; i+=2) { void *vattrinfo; struct _valid_attr_t *attrinfo; char *attr = argv[i], *val = NULL; if(!strcasecmp(argv[i], "no")) attr = argv[i+1]; else val = argv[i+1]; if(!noit_hash_retrieve(&check_attrs, attr, strlen(attr), &vattrinfo)) { error = 1; break; } attrinfo = vattrinfo; /* The fixation stuff doesn't matter here, this check is brand-new */ xmlUnsetProp(node, (xmlChar *)attrinfo->name); if(val) xmlSetProp(node, (xmlChar *)attrinfo->name, (xmlChar *)val); noit_conf_mark_changed(); } return error; }
bool gpl::xml::erasePropertyByXPath(const char* propName) { if (m_xml->resource == NULL) return false; if (strlen(propName) == 0) return true; //cout<<"resource->type:"<<m_xml->resource->type<<endl; switch (m_xml->resource->type) { case XPATH_NODESET://Object is a Node Set if (m_xml->resource->nodesetval == NULL) return false; xmlNodePtr cur; //取得第一个节点 if ((cur = (*(m_xml->resource->nodesetval->nodeTab))) == NULL) return false; xmlUnsetProp(cur, (const xmlChar*)propName); break; case XPATH_XSLT_TREE://Object is an XSLT value tree case XPATH_BOOLEAN://Object is a Boolean case XPATH_NUMBER://Object is a number case XPATH_STRING://Object is a string case XPATH_POINT://Object is a point case XPATH_RANGE://是一个范围 case XPATH_LOCATIONSET://Object is a Location Set case XPATH_USERS://Object is user defined case XPATH_UNDEFINED://Object is uninitialized return false; break; } return true; }
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 ThreadedBlock::postInvoke(Context *ctx, InvokeContext *invoke_ctx) { Block::postInvoke(ctx, invoke_ctx); if (invoke_ctx->error()) { return; } bool show_elapsed_time = trb_data_->check_elapsed_time_ ? trb_data_->check_elapsed_time_ : OperationMode::instance()->checkDevelopmentVariable(ctx->request(), ThreadedBlockData::SHOW_ELAPSED_TIME); if (!show_elapsed_time || tagged()) { return; } xmlNodePtr node = xmlDocGetRootElement(invoke_ctx->resultDoc().get()); if (NULL == node) { return; } const xmlChar* elapsed_attr = (const xmlChar*)"elapsed-time"; std::string elapsed = boost::lexical_cast<std::string>(0.001*ctx->timer().elapsed()); if (xmlHasProp(node, elapsed_attr) && xmlUnsetProp(node, elapsed_attr) < 0) { log()->error("Cannot unset elapsed-time attribute"); return; } xmlNewProp(node, elapsed_attr, (const xmlChar*)elapsed.c_str()); }
// void removeAttribute(in DOMString name) raises(DOMException); static void _removeAttribute(Request& r, MethodParams& params) { const xmlChar* name=as_xmlname(r, params, 0); VXnode& vnode=GET_SELF(r, VXnode); xmlNode& element=get_self_element(vnode); // @todo: when name="xmlns" xmlUnsetProp(&element, name); }
bool CSpmXml::DeleteAttr(const QString& strAttrName, xmlNodePtr pNode) { pNode = GetNode(pNode); if (0 == pNode) return false; bool bRes = (0 == xmlUnsetProp(pNode, BAD_CAST strAttrName.toUtf8().data())); if (bRes) SetModified(); return bRes; }
static void noit_conf_check_bump_seq(xmlNodePtr node) { int64_t seq; xmlChar *seq_str; seq_str = xmlGetProp(node, (xmlChar *)"seq"); if(!seq_str) return; seq = strtoll((const char *)seq_str, NULL, 10); if(seq != 0) { char new_seq_str[64]; /* negatve -> 0, positive ++ */ seq = (seq < 0) ? 0 : (seq + 1); snprintf(new_seq_str, sizeof(new_seq_str), "%" PRIi64, seq); xmlUnsetProp(node, (xmlChar *)"seq"); xmlSetProp(node, (xmlChar *)"seq", (xmlChar *)new_seq_str); } xmlFree(seq_str); }
/** @brief Add an integer property to a XML node. * * If a property with this name already exists it is overwritten. * * @param cur Pointer to the XML node. * @param prop Name of the property. * @param value Value of the property. */ static void parser_newprop_int(xmlNodePtr cur, const xmlChar *prop, int value) { xmlChar *temp; temp=xmlGetProp(cur, prop); if(temp!=NULL) { xmlUnsetProp(cur, prop); } xmlFree(temp); temp=malloc(sizeof(*temp)*LINEBUFFSIZE); if(temp==NULL) fatal(_("Can't allocate memory")); xmlStrPrintf(temp, LINEBUFFSIZE, XMLCHAR "%d", value); xmlNewProp(cur, prop, temp); free(temp); }
/* rc = TRUE if orig_cib has been filtered * That means '*result' rather than 'xml' should be exploited afterwards */ static bool __xml_purge_attributes(xmlNode *xml) { xmlNode *child = NULL; xmlAttr *xIter = NULL; bool readable_children = FALSE; xml_private_t *p = xml->_private; if (__xml_acl_mode_test(p->flags, xpf_acl_read)) { crm_trace("%s[@id=%s] is readable", crm_element_name(xml), ID(xml)); return TRUE; } xIter = xml->properties; while (xIter != NULL) { xmlAttr *tmp = xIter; const char *prop_name = (const char *)xIter->name; xIter = xIter->next; if (strcmp(prop_name, XML_ATTR_ID) == 0) { continue; } xmlUnsetProp(xml, tmp->name); } child = __xml_first_child(xml); while ( child != NULL ) { xmlNode *tmp = child; child = __xml_next(child); readable_children |= __xml_purge_attributes(tmp); } if (readable_children == FALSE) { free_xml(xml); /* Nothing readable under here, purge completely */ } return readable_children; }
static int replace_attr(noit_console_closure_t ncct, noit_conf_t_userdata_t *info, struct _valid_attr_t *attrinfo, const char *value) { int i, cnt, rv = -1, active = 0; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; xmlNodePtr node; char xpath[1024], *path; path = info->path; if(!strcmp(path, "/")) path = ""; noit_conf_xml_xpath(NULL, &xpath_ctxt); if(attrinfo->checks_fixate) { /* Only if checks will fixate this attribute shall we check for * child <check> nodes. * NOTE: this return nothing and "seems" okay if we are _in_ * a <check> node. That case is handled below. */ snprintf(xpath, sizeof(xpath), "/noit/%s//check[@uuid]", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); for(i=0; i<cnt; i++) { uuid_t checkid; node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); if(noit_conf_get_uuid(node, "@uuid", checkid)) { noit_check_t *check; check = noit_poller_lookup(checkid); if(check && NOIT_CHECK_LIVE(check)) active++; } } if(pobj) xmlXPathFreeObject(pobj); } snprintf(xpath, sizeof(xpath), "/noit/%s", path); pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET) goto out; cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); if(cnt != 1) { nc_printf(ncct, "Internal error: context node disappeared\n"); goto out; } node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, 0); if(attrinfo->checks_fixate && !strcmp((const char *)node->name, "check")) { uuid_t checkid; /* Detect if we are actually a <check> node and attempting to * change something we shouldn't. * This is the counterpart noted above. */ if(noit_conf_get_uuid(node, "@uuid", checkid)) { noit_check_t *check; check = noit_poller_lookup(checkid); if(check && NOIT_CHECK_LIVE(check)) active++; } } if(active) { nc_printf(ncct, "Cannot set '%s', it would effect %d live check(s)\n", attrinfo->name, active); goto out; } xmlUnsetProp(node, (xmlChar *)attrinfo->name); if(value) xmlSetProp(node, (xmlChar *)attrinfo->name, (xmlChar *)value); noit_conf_mark_changed(); rv = 0; out: if(pobj) xmlXPathFreeObject(pobj); return rv; }
static int noit_console_config_nocheck(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { int i, cnt; const char *err = "internal error"; noit_conf_t_userdata_t *info; xmlXPathObjectPtr pobj = NULL; xmlXPathContextPtr xpath_ctxt = NULL; char xpath[1024]; uuid_t checkid; noit_conf_xml_xpath(NULL, &xpath_ctxt); if(argc < 1) { nc_printf(ncct, "requires one argument\n"); return -1; } info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); if(noit_console_mkcheck_xpath(xpath, sizeof(xpath), info, argv[0])) { nc_printf(ncct, "could not find check '%s'\n", argv[0]); return -1; } pobj = xmlXPathEval((xmlChar *)xpath, xpath_ctxt); if(!pobj || pobj->type != XPATH_NODESET || xmlXPathNodeSetIsEmpty(pobj->nodesetval)) { err = "no checks found"; goto bad; } cnt = xmlXPathNodeSetGetLength(pobj->nodesetval); for(i=0; i<cnt; i++) { xmlNodePtr node; char *uuid_conf; node = (noit_conf_section_t)xmlXPathNodeSetItem(pobj->nodesetval, i); uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid"); if(!uuid_conf || uuid_parse(uuid_conf, checkid)) { nc_printf(ncct, "%s has invalid or missing UUID!\n", (char *)xmlGetNodePath(node) + strlen("/noit")); } else { if(argc > 1) { int j; for(j=1;j<argc;j++) xmlUnsetProp(node, (xmlChar *)argv[j]); } else { nc_printf(ncct, "descheduling %s\n", uuid_conf); noit_poller_deschedule(checkid); xmlUnlinkNode(node); } noit_conf_mark_changed(); } } if(argc > 1) { noit_poller_process_checks(xpath); noit_poller_reload(xpath); } nc_printf(ncct, "rebuilding causal map...\n"); noit_poller_make_causal_map(); if(pobj) xmlXPathFreeObject(pobj); return 0; bad: if(pobj) xmlXPathFreeObject(pobj); nc_printf(ncct, "%s\n", err); return -1; }
ReturnCode saveExternalFiles(xmlNodePtr aNodePtr, TixiDocument* aTixiDocument) { TixiDocumentHandle handle = aTixiDocument->handle; xmlNodePtr cur_node = NULL; xmlNodePtr copiedNode = NULL; char* externalDataDirectory = NULL; char* externalFileName = NULL; char* fullExternalFileName = NULL; char* externalDataNodePath = NULL; char* fullExternalDataNodePath = NULL; xmlDocPtr xmlDocument = NULL; /* find external data nodes */ for (cur_node = aNodePtr; cur_node; cur_node = cur_node->next) { /* recurse down with the next element */ saveExternalFiles(cur_node->children, aTixiDocument); if( checkExternalNode( cur_node ) != SUCCESS) { continue; } if ( cur_node->type == XML_ELEMENT_NODE ) { char* dirResolved = NULL; char* includetNodeName = (char*) xmlGetNodePath(cur_node); /* collect node information - externalFileName */ tixiGetTextAttribute(handle, includetNodeName, EXTERNAL_DATA_XML_ATTR_FILENAME, &externalFileName); /* collect node information - externalDataDirectory */ tixiGetTextAttribute(handle, includetNodeName, EXTERNAL_DATA_XML_ATTR_DIRECTORY, &externalDataDirectory); /* collect node information - externalDataNodePath */ tixiGetTextAttribute(handle, includetNodeName, EXTERNAL_DATA_XML_ATTR_NODEPATH, &externalDataNodePath); free(includetNodeName); /* remove attributes */ xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_FILENAME); xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_DIRECTORY); xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_NODEPATH); /* create new document */ xmlDocument = xmlNewDoc((xmlChar*) "1.0"); if (!xmlDocument) { printMsg(MESSAGETYPE_ERROR, "Error in TIXI::saveExternalFiles ==> Could not create new document.\n"); return FAILED; } /* deep copy of nodes from external files */ copiedNode = xmlDocCopyNode(cur_node, xmlDocument, 1); xmlDocSetRootElement(xmlDocument, copiedNode); dirResolved = resolveDirectory(aTixiDocument->dirname, externalDataDirectory); /* only save to local paths */ if(string_startsWith(dirResolved, "file://") == 0) { char* externalDataDirectoryNotUrl = uriToLocalPath(dirResolved); assert(externalDataDirectoryNotUrl); fullExternalFileName = buildString("%s%s", externalDataDirectoryNotUrl, externalFileName); xmlSaveFormatFileEnc(fullExternalFileName, xmlDocument, "utf-8", 1); free(fullExternalFileName); free(externalDataDirectoryNotUrl); } free(dirResolved); xmlFreeDoc(xmlDocument); /* create external data node structure */ fullExternalDataNodePath = buildString("%s/%s", externalDataNodePath, EXTERNAL_DATA_NODE_NAME); /* add parent node if not exists */ if(tixiCheckElement(handle, fullExternalDataNodePath) != SUCCESS) { tixiAddTextElement(handle, externalDataNodePath, EXTERNAL_DATA_NODE_NAME, ""); tixiAddTextElement(handle, fullExternalDataNodePath, EXTERNAL_DATA_NODE_NAME_PATH, externalDataDirectory); } /* add node for external reference */ tixiAddTextElement(handle, fullExternalDataNodePath, EXTERNAL_DATA_NODE_NAME_FILENAME, externalFileName); /* remove the copied nodes from document*/ copiedNode = cur_node->prev; xmlUnlinkNode(cur_node); xmlFreeNode(cur_node); free(fullExternalDataNodePath); cur_node = copiedNode; } } return SUCCESS; }