急急急急急!用c++分割xml文件

来源:百度知道 编辑:UC知道 时间:2024/05/02 20:56:30
急急急!!!!
c++高手们,帮忙帮小弟解决个问题吧,小弟没做过c++,帮帮忙吧,问题就是这样把一个文件
in.xml文件
<a>
<store id=001>
<name></name>
</store>
<store id=002>
<name></name>
</store>
</a>
处理成:
out1.xml
<a>
<store id=001>
<name></name>
</store>
</a>
out2.xml
<a>
<store id=002>
<name></name>
</store>
</a>
处理的依据就是store id=?
if store id=001出力到out1.xml
if store id=002出力到out2.xml
用Vc++做成一个exe,要在dos下执行,执行格式:
tool.exe in out1 out2 即可完成此处理
小弟想了好几天了,实在具体实施不了,谁能帮帮小弟啊,小弟什么都愿意帮您做,谢谢大家了!!!!

确实不容易,10分太少。

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

#define MAX_LINE_LEN 256
#define MAX_FILENAME_LENGTH 256

typedef vector<string> nodes;
typedef unsigned int uint;

// Read an XML file into an array of
// {,<,>,<,>,<,>,}
nodes ReadFileToNodes(const char* filename){
vector<string> res;
ifstream fin(filename, ios::binary );
char line[MAX_LINE_LEN];
while(!fin.eof())
{
fin.getline(line,MAX_LINE_LEN);

// delete the ending \n char
if(line[strlen(line)-1]=='\n')
line[strlen(line)-1]='\0';

char* tag;
tag = strtok(line,"<");

while(tag!=NULL)
{
string t = "<"; // find it back
t.append(tag);
res.insert(res.end(), t