2012-02-11 14:46:19|?次阅读|上传:wustguangh【已有?条评论】发表评论
关键词:C/C++, XML, 数据库|来源:唯设编程网
4.删除元素
CMarkup xml; xml.Load("UserInfo.xml"); BOOL bFind = true; xml.ResetMainPos(); while (bFind) { bFind = xml.FindChildElem("UserID"); if (bFind) { //此时接点还是父接点 CString strData = _T(""); strData = xml.GetChildData(); if (strData=="luo") { xml.RemoveChildElem(); xml.Save("UserInfo.xml"); break; } } }
》测试用XML文件2:
见第二点浏览。类似
上面的例子里面没有属性这些东西,下面的一个例子是有属性的
//UserInfo1.xml
<?xml version="1.0" encoding="UTF-8" ?> <UserInfo> <User UserID="UserID00" UserPwd="UserPwd00" UserLevel="158" /> <User UserID="UserID01" UserPwd="UserPwd01" UserLevel="162" /> <User UserID="UserID02" UserPwd="UserPwd02" UserLevel="165" /> <User UserID="UserID03" UserPwd="UserPwd03" UserLevel="168" /> <User UserID="UserID04" UserPwd="UserPwd04" UserLevel="171" /> <User UserID="UserID05" UserPwd="UserPwd05" UserLevel="175" /> <User UserID="UserID06" UserPwd="UserPwd06" UserLevel="178" /> <User UserID="UserID07" UserPwd="UserPwd07" UserLevel="181" /> <User UserID="UserID08" UserPwd="UserPwd08" UserLevel="184" /> <User UserID="UserID09" UserPwd="UserPwd09" UserLevel="188" /> </UserInfo>
》产生文件
CString strID = _T(""); CString strPwd = _T(""); CMarkup xml; xml.SetDoc("<?xml version="1.0" encoding="UTF-8"?>"); xml.AddElem("UserInfo"); xml.IntoElem(); for (int i=0; i<10; i++) { //产生一个随机数,作为权限 srand(UINT(time(NULL)+i)); int nLevel = rand()%256; strID.Format("UserID%02d",i); strPwd.Format("UserPwd%02d",i); xml.AddElem("User"); xml.AddAttrib("UserID",strID); xml.AddAttrib("UserPwd",strPwd); xml.AddAttrib("UserLevel",nLevel); } xml.OutOfElem(); xml.Save("UserInfo1.xml");