void startDialog::on_Setting_clicked() { dialogCloseHelper _helperClose(this) ; XMLDialog xmlDlg(NULL); ndxml_root *pConfig = apoEditorSetting::getInstant()->getIoConfig(); if (pConfig) { xmlDlg.showXml(pConfig, "EditorConfig"); if (xmlDlg.exec() == QDialog::Accepted) { std::string &ioConfigFile = apoEditorSetting::getInstant()->m_projConfigFile ; //nd_chdir(nd_getcwd()); ndxml_save(pConfig, ioConfigFile.c_str()); WriteLog("save script ok\n"); } else { WriteLog("script unedited\n"); } } }
int set_xml_value(char *file, char *node_name_list, char *attr_name, char*attr_val, char *node_val) { int ret; ndxml_root xmlfile; ndxml *xnode = 0 ; char *p = node_name_list; char name[128] ; ret = ndxml_load(file, &xmlfile) ; if(0!=ret) { fprintf(stderr,"load xml from %s\n", file) ; return -1; } p = (char*)ndstr_nstr_end(p, name, '.', sizeof(name)) ; if (IS_NUMERALS(name[0])) { xnode = ndxml_getnodei(&xmlfile, ndstr_atoi_hex(name)); } else { xnode = ndxml_getnode(&xmlfile, name) ; } if (!xnode) { fprintf(stderr,"read xml-node %s error \n", name) ; } bool success = true ; while (p && *p) { if (*p == '.') { ++p ; if (!*p) { break ; } } p = (char*) ndstr_nstr_end(p, name, '.', sizeof(name)) ; if (IS_NUMERALS(name[0])) { xnode = ndxml_refsubi(xnode, ndstr_atoi_hex(name)); } else { xnode = ndxml_refsub(xnode, name) ; } if (!xnode) { fprintf(stderr,"read xml-node %s error \n", name) ; success = false ; break ; } } if (success) { success = false; if (attr_name && attr_name[0] && attr_val && attr_val[0]) { ndxml_setattrval(xnode,attr_name, attr_val ) ; success = true ; } if (node_val && node_val[0]) { ndxml_setval(xnode, node_val) ; success = true ; } if (success) { ndxml_save(&xmlfile,file) ; } } ndxml_destroy(&xmlfile); return success ? 0: -1 ; }