利用TingXML读XML文件

编程入门 行业动态 更新时间:2024-10-22 14:44:18

利用TingXML读XML<a href=https://www.elefans.com/category/jswz/34/1771438.html style=文件"/>

利用TingXML读XML文件

                                                                        利用TingXML读XML文件
①待读取的xml文件

②程序

#include"tinyxml2.h"
#include<iostream>
using namespace tinyxml2;
using namespace std;//<?xml version="1.0" encoding="utf-8"?>
//<!-- This is a XML comment! -->
//<note>
//  <program type="c++">
//      <title language="english" id="12138">Read XML</title>
//      <author>Jay</author>
//      <time>2019</time>
//  </program>
//</note>int main()
{XMLDocument *doc=new XMLDocument;doc->LoadFile("write.xml");auto pNote=doc->FirstChildElement();cout<<pNote->Name()<<endl;auto pProgram=pNote->FirstChildElement();cout<<pProgram->Name()<<":";cout<<pProgram->FirstAttribute()->Name()<<" ";cout<<pProgram->FirstAttribute()->Value()<<endl;auto pTitle=pProgram->FirstChildElement();while(pTitle){cout<<pTitle->Name()<<":"<<pTitle->GetText()<<"\t";auto pTitleAtrr=pTitle->FirstAttribute();while(pTitleAtrr)//通过循环得到属性{cout<<pTitleAtrr->Name()<<":"<<pTitleAtrr->Value()<<" ";pTitleAtrr=pTitleAtrr->Next();}cout<<endl;pTitle=pTitle->NextSiblingElement();}delete doc;return 0;
}

③效果

更多推荐

利用TingXML读XML文件

本文发布于:2024-02-06 03:25:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1746046.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   TingXML   XML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!