,下面的一个例子是有属性的
view plaincopy to clipboardprint?
//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> //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> //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> //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>
7. 产生
view plaincopy to clipboardprint?
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"); 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"); 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"); 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",
asics running sneakers,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");
8. 查找
view plaincopy to clipboardprint?
CMarkup xml; BOOL bLoad = false; BOOL bFind = false; bLoad = xml.Load("UserInfo1.xml"); if (bLoad) { CString strID; CString strPwd; xml.ResetMainPos(); xml.FindElem(); //UserInfo while (xml.FindChildElem("User")) { strID = xml.GetChildAttrib("UserID"); strPwd = xml.GetChildAttrib("UserPwd"); TRACE("\n----id:%s,pwd:%s-------\n",
glasses armani,strID,strPwd); if (strID=="UserID00"&&strPwd=="UserPwd00") { bFind = true; break; } } } if (bFind) { TRACE("\n---- find------\n"); } else { TRACE("\n----no find------\n"); } CMarkup xml; BOOL bLoad = false; BOOL bFind = false; bLoad = xml.Load("UserInfo1.xml"); if (bLoad) { CString strID; CString strPwd; xml.ResetMainPos(); xml.FindElem(); //UserInfo while (xml.FindChildElem("User")) { strID = xml.GetChildAttrib("UserID"); strPwd = xml.GetChildAttrib("UserPwd"); TRACE("\n----id:%s,pwd:%s-------\n",strID,strPwd); if (strID=="UserID00"&&strPwd=="UserPwd00") { bFind = true; break; } } } if (bFind) { TRACE("\n---- find------\n"); } else { TRACE("\n----no find------\n"); } CMarkup xml; BOOL bLoad = false; BOOL bFind = false; bLoad = xml.Load("UserInfo1.xml"); if (bLoad) { CString strID; CString strPwd; xml.ResetMainPos(); xml.FindElem(); //UserInfo while (xml.FindChildElem("User")) { strID = xml.GetChildAttrib("UserID"); strPwd = xml.GetChildAttrib("UserPwd"); TRACE("\n----id:%s,pwd:%s-------\n",strID,
red wing work boot,strPwd); if (strID=="UserID00"&&strPwd=="UserPwd00") { bFind = true; break; } } } if (bFind) { TRACE("\n---- find------\n"); } else { TRACE("\n----no find------\n"); } CMarkup xml; BOOL bLoad = false; BOOL bFind = false; bLoad = xml.Load("UserInfo1.xml"); if (bLoad) { CString strID; CString strPwd; xml.ResetMainPos(); xml.FindElem(); //UserInfo while (xml.FindChildElem("User")) { strID = xml.GetChildAttrib("UserID"); strPwd = xml.GetChildAttrib("UserPwd"); TRACE("\n----id:%s,pwd:%s-------\n",strID,strPwd); if (strID=="UserID00"&&strPwd=="UserPwd00") { bFind = true; break; } } } if (bFind) { TRACE("\n---- find------\n"); } else { TRACE("\n----no find------\n"); }
9. 修正
view plaincopy to clipboardprint?
CMarkup xml; BOOL bLoad = false; BOOL bFind = false; bLoad = xml.Load("UserInfo1.xml"); if (bLoad) { CString strID; CString strPwd; xml.ResetMainPos(); xml.FindElem(); //UserInfo while (xml.FindChildElem("User")) { strID = xml.GetChildAttrib("UserID"); strPwd = xml.GetChildAttrib("UserPwd"); TRACE("\n----id:%s,pwd:%s-------\n",strID,strPwd); if (strID=="UserID00"&&strPwd=="UserPwd00") { bFind = true; xml.SetChildAttrib("UserID",strID+CString("Modify" )); xml.Save("UserInfo1.xml"); break; } } } if (bFind) { TRACE("\n---- find------\n"); } else { TRACE("\n----no find------\n"); } CMarkup xml; BOOL bLoad = false; BOOL bFind = false; bLoad = xml.Load("UserInfo1.xml"); if (bLoad) { CString strID; CString strPwd; xml.ResetMainPos(); xml.FindElem(); //UserInfo while (xml.FindChildElem("User")) { strID = xml.GetChildAttrib("UserID"); strPwd = xml.GetChildAttrib("UserPwd"); TRACE("\n----id:%s,pwd:%s-------\n",strID,strPwd); if (strID=="UserID00"&&strPwd=="UserPwd00") { bFind = true; xml.SetChildAttrib("UserID",
new supra,strID+CString("Modify")); xml.Save("UserInfo1.xml"); break; } } } if (bFind) { TRACE("\n---- find------\n"); } else { TRACE("\n----no find------\n"); }
CMarkup字符集问题
daubwu posted @ 2008年9月08日 00:54 in VC with tags XML CMarkup , 38 浏览
CMarkup支撑Unicode,_MBCS宏定义。VS默认设置为MBCS宏定义,未设置该宏时为 UTF-8编码。
有 MBCS宏定义,且 打开的文件是UTF-8编码:
CMarkup在Load时将UTF-8转换ANSI编码格局,所以要在读取的处所设置
view plaincopy to clipboardprint?
#include <locale.h> setlocale(LC_ALL, ""); #include <locale.h>setlocale(LC_ALL, "");
不MBCS宏定义,且翻开的文件是UTF-8编码:
系统默认将文件按UTF-8格式读入体系中,所以显示的时候要手动将数据转换为ANSI格式的进行显示
view plaincopy to clipboardprint?
#include <locale.h> setlocale(LC_ALL, ""); strVal = CMarkup::UTF8ToA(strVal); #include <locale.h>setlocale(LC_ALL, "");strVal = CMarkup::UTF8ToA(strVal);
PS:通过strcpy等拷贝函数能够修改。