c++ tinyxml2解析xml多个属性

China☆狼群 提交于 2020-02-07 07:30:23

需要解析xml的多个属性,找到下载资源中的test文件,可以使用Next()指向当前下个XmlAttribure。

#include “reconvertXml.h”

using namespace std;
using namespace tinyxml2;

int handleSipMessage()
{
string aa = “<?xml version=\"1.0\" encoding=\"UTF-8\"?><SIP_XML EventType=“Request_Resource” a=“3”><Item Code=“地址” FromIndex=“期望返回的起始记录数” ToIndex=“期望返回的结束记录数”/></SIP_XML>”;
XMLDocument doc;
doc.Parse(aa.c_str());
XMLElement* SIPXML = doc.RootElement();
const XMLAttribute * eventTypeAttr = SIPXML->FirstAttribute();
string eventType = eventTypeAttr->Value();
cout<<eventType<<endl;
if(eventType == “Request_Resource”)
{
cout<<“request_resource”<<endl;
XMLElement* item = SIPXML->FirstChildElement(“Item”);
const XMLAttribute* a = item->FirstAttribute();
string code = a->Value();
cout<<code<<endl;
a= a->Next();
string fromIndex = a->Value();
cout<<fromIndex<<endl;
a= a->Next();
string toIndex = a->Value();
cout<<toIndex<<endl;

        }

  return 0;

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!