#include
#include
#include
#include
#include
#include
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_iterators.hpp"
#include "rapidxml/rapidxml_print.hpp"
#include "rapidxml/rapidxml_utils.hpp"
using namespace std;
void FindFile(char * lpPath, vector &vec)
{
char strTemp[255];
char szFind[255];
char temp[255];
string str = "";
WIN32_FIND_DATA FindFileData;
strcpy(szFind,lpPath);
strcpy(temp,lpPath);
strcat(szFind,"\\*.*");
HANDLE hFind=::FindFirstFile(szFind,&FindFileData);
if(INVALID_HANDLE_VALUE == hFind) return;
cout<<"遍历放入vec中的路径名字:"<<endl;
while(TRUE)
{
if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(FindFileData.cFileName[0]!='.')
{
strcpy(szFind,lpPath);
strcat(szFind,"\\");
strcpy(temp,lpPath);
strcat(temp,"\\");
strcat(szFind,FindFileData.cFileName);
FindFile(szFind,vec);
}
}
else
{
strcpy(strTemp,temp);
strcat(strTemp,"\\");
strcat(strTemp,FindFileData.cFileName);
str = FindFileData.cFileName;
if(str.find_first_of(".") > 0)
{
str = str.substr(str.find_last_of(".") + 1,str.length());
if(str == "xml")
{
vec.push_back(strTemp);
cout<<strTemp<<endl;
}
}
}
if(!FindNextFile(hFind,&FindFileData))
break;
}
FindClose(hFind);
}
void getInfo(string strFileName,vector &vec)
{
fstream infile;
string temp = "";
string publish = "";
string::size_type loc;
infile.open(strFileName.c_str());
if(infile.fail())
{
cout << "can not open the file";
}
while(!infile.eof())
{
getline(infile,temp);
loc = temp.find("PublishData");
if(loc != string::npos)
{
publish = temp.substr(loc + 13,1);
if(publish == "1")
{
vec.push_back(temp);
cout<<temp<<endl;
}
}
}
}
void LoadInfo(string strFileName)
{
fstream infile;
string temp = "";
string publish = "";
string::size_type loc;
infile.open(strFileName.c_str());
while(!infile.eof())
{
getline(infile,temp);
loc = temp.find("PublishData");
if(loc != string::npos)
{
publish = temp.substr(loc + 13,1);
if(publish == "0")//已经找到所有pubdata=0的情况,如何利用rapidxml.attribute时问题所在
{
rapidxml::xml_document<char> xmlDoc;
rapidxml::xml_node<>* root = xmlDoc.first_node();
//问题在这里 。在这里如何做东西!!!!!
}
}
}
}
void main()
{
vector s;
vector vec;
//FindFile("E:\work\Game",s);
FindFile("F:\test",s);
vector::iterator it;
for(it = s.begin();it!= s.end();it++)
{
string filepath = *it;
FILE *pFile = fopen(filepath.c_str(),"a+");
if(pFile)
{
//getInfo(filepath.c_str(), vec);
LoadInfo(filepath.c_str());
fclose(pFile);
}
}
system("pause");
//将存储在容器中的地址。一个个打开进型行标记查找
}
Q:问题部分我已经“//”贴出来了,问题是我已经把所有xml文件地址遍历了,然后删选关键字,想把所有publishdata=0的属性全部剔除。请问如何做。例子:
xxxxx.xml
我如何剔除publishdata=0的一行属性。然后最后保存的时候只有publishdata=1的数据