上次是从XML文件里读取节点, 很简单, 这次把修改调通了.
CString csLogPath;
m_edit_logpath.GetWindowText(csLogPath);
TiXmlElement* pElmChild = NULL; // 一个指向Element的指针
TiXmlElement* pElmRoot = NULL; // 根节点
TiXmlDeclaration Declaration( "1.0","utf-8", "yes" ); // 建立XML头结构
char sFilePath[MAX_PATH];
memset(sFilePath,0,sizeof(sFilePath));
strcpy(sFilePath,DEFAULT_CFG_PATH);
strcat(sFilePath,"//config.xml");
TiXmlDocument xmlDoc( sFilePath ); // 用存档的文件名字来建立一个XML文件
xmlDoc.LoadFile();
TiXmlNode * node = NULL;
node = xmlDoc.FirstChild( XML_CFG_ROOT_ELM );
if( !node ) {
MessageBox("get node失败!", "提示", NULL);
return;
}
pElmChild = node->ToElement();
char * pszEle000 = (char *)pElmChild->GetText();
node = pElmChild->FirstChild(XML_CFG_CHILD_ELM_1);
node = pElmChild->FirstChild(XML_CFG_CHILD_ELM_2);
pElmChild = node->ToElement();
char * pszEle111 = (char *)pElmChild->GetText();//取值
node->Clear();//必须先清除一下
TiXmlText newText(csLogPath.GetBuffer(0));
//node->SetValue(XML_CFG_CHILD_ELM_2);//改变节点的名字
node->InsertEndChild(newText);//只用这句就行了, 不过还是觉得有点不方便
//node->LinkEndChild(newText);//网上所有的资料都是用这句,可惜连编译都通不过,操蛋
//node->ReplaceChild( node, newText );//把节点的名字也替换掉了
DWORD err = GetLastError();
xmlDoc.SaveFile();
不知网上其他人发的程序是否真正调试过, 随便从别的地方抄过来就害人, 太不负责任了......