c++ tinyxml2解析xml多个属性

需要解析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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值