求大神看看,怎么把xml解析结果保存到txt里面,就两个节点保存就行,该怎么写到代码
#include <iostream>
#include <string>
using namespace std;
#include "tinyxml.h"
void parseXml(TiXmlNode* node) { for (TiXmlElement* nodeEle = node->FirstChildElement(); nodeEle != nullptr; nodeEle = nodeEle->NextSiblingElement()) { TiXmlNode* tempEle = nodeEle; if (nodeEle->GetText() != NULL) { string tag = nodeEle->Value(); string content = nodeEle->GetText(); cout << "tag:" << tag << endl; cout << "\t\t" << "content:" << content << endl; } if (!tempEle->NoChildren()) { parseXml(tempEle); } }}
int main()
{ string strfile; cout << "input xml file name:"; cin >> strfile; TiXmlDocument doc(strfile.c_str()); if (doc.LoadFile()) { parseXml(doc.RootElement()); } else cout << "no xml found!!!" << endl; }
就是将tag和content保存到文本里面,这个该怎么写代码呀?