91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

資源包含2015.9.23從官網(wǎng)下載的tinyxml2的源碼和自己編寫的示例代碼還有介紹文檔,容易上手。官網(wǎng)的示例代碼和文檔晦澀難懂,才自己整理。

資源截圖

代碼片段和文件信息

#include?
#include?
using?namespace?std;

#include?“tinyxml2.h“
using?namespace?tinyxml2;

//將數(shù)字轉(zhuǎn)換成字符串
string?itoa(int?num)
{
stringstream?ss;
ss?< return?ss.str();
}

class?User
{
public:
User(){
gender=0;
};

User(const?string&?userName?const?string&?password?int?gender?const?string&?mobile?const?string&?email){
this->userName=userName;
this->password=password;
this->gender=gender;
this->mobile=mobile;
this->email=email;
};

string?userName;
string?password;
int?gender;
string?mobile;
string?email;
};

//function:create?a?xml?file
//param:xmlPath:xml文件路徑
//return:0成功,非0,失敗
int?createxml(const?char*?xmlPath)
{
const?char*?declaration?=“l?version=\“1.0\“?encoding=\“UTF-8\“?standalone=\“no\“?>“;
xmlDocument?doc;
doc.Parse(declaration);//會覆蓋xml所有內(nèi)容

//添加默認(rèn)的申明可以使用如下兩行
//xmlDeclaration*?declaration=doc.NewDeclaration();
????//doc.InsertFirstChild(declaration);

xmlElement*?root=doc.NewElement(“DBUSER“);
doc.InsertEndChild(root);

return?doc.SaveFile(xmlPath);
}

//function:insert?xml?node
//param:xmlPath:xml文件路徑;?user:用戶對象
//return:0:成功;?非0:失敗
int?insertxmlNode(const?char*?xmlPathconst?User&?user)
{
xmlDocument?doc;
int?res=doc.LoadFile(xmlPath);
if(res!=0)
{
cout<<“l(fā)oad?xml?file?failed“< return?res;
}
xmlElement*?root=doc.RootElement();

xmlElement*?userNode?=?doc.NewElement(“User“);
userNode->SetAttribute(“Name“user.userName.c_str());
userNode->SetAttribute(“Password?“user.password.c_str());
root->InsertEndChild(userNode);

xmlElement*?gender?=?doc.NewElement(“Gender“);
xmlText*?genderText=doc.NewText(itoa(user.gender).c_str());
gender->InsertEndChild(genderText);
userNode->InsertEndChild(gender);

xmlElement*?mobile?=?doc.NewElement(“Mobile“);
mobile->InsertEndChild(doc.NewText(user.mobile.c_str()));
userNode->InsertEndChild(mobile);

xmlElement*?email?=?doc.NewElement(“Email“);
email->InsertEndChild(doc.NewText(user.email.c_str()));
userNode->InsertEndChild(email);

return?doc.SaveFile(xmlPath);
}

//function:根據(jù)用戶名獲取用戶節(jié)點(diǎn)
//param:root:xml文件根節(jié)點(diǎn);userName:用戶名
//return:用戶節(jié)點(diǎn)
xmlElement*?queryUserNodeByName(xmlElement*?rootconst?string&?userName)
{

xmlElement*?userNode=root->FirstChildElement(“User“);
while(userNode!=NULL)
{
if(userNode->Attribute(“Name“)==userName)
break;
userNode=userNode->NextSiblingElement();//下一個兄弟節(jié)點(diǎn)
}
return?userNode;
}

User*?queryUserByName(const?char*?xmlPathconst?string&?userName)
{
xmlDocument?doc;
if(doc.LoadFile(xmlPath)!=0)
{
cout<<“l(fā)oad?xml?file?failed“< return?NULL;
}
xmlElement*?root=doc.RootElement();
xmlElement*?userNode=queryUserNodeByName(rootuserName);
cout<<“end?query?UserNode“<
if(userNode!=NULL)??//searched?successfully
{
cout<<“userNode?exist“< User*?user=new?User();
user->userName=userName;
//string?passwordAttr=userNod

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????8000??2015-09-26?11:05??tinyxml2\main.cpp

?????文件????????296??2015-09-25?18:30??tinyxml2\makefile

?????文件??????64220??2015-08-20?07:37??tinyxml2\tinyxml2.cpp

?????文件??????63676??2015-08-20?07:37??tinyxml2\tinyxml2.h

?????文件??????31441??2015-09-26?11:12??tinyxml2\tinyxml2簡介與用法用例.docx

?????文件?????????54??2015-09-26?10:40??tinyxml2\user.xml

?????目錄??????????0??2015-09-26?11:12??tinyxml2

-----------?---------??----------?-----??----

???????????????167687????????????????????7


評論

共有 條評論