求大神看看,怎么把xml解析结果保存到txt里面,就两个节点保存就行,该怎么写到代码

m0_57558491 2021-05-01 11:22:07
#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保存到文本里面,这个该怎么写代码呀?
...全文
41 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧