c++ 解析xml的小工具tinyxml

例子:

person.xml

  1 <Persons>
  2     <Person ID="1">
  3         <name>phinecos</name>
  4         <age>22</age>
  5     </Person>
  6 </Persons>

 

c++测试代码:

  1 #include <iostream>
  2 #include "tinyxml.h"
  3 #include "tinystr.h"
  4 #include <string>
  5
  6 using namespace std;
  7
  8
  9 int main(){
 10         TiXmlDocument* myDocument = new TiXmlDocument();
 11         myDocument->LoadFile("person.xml");
 12         TiXmlElement* rootElement = myDocument->RootElement();
 13         cout << rootElement->Value() << endl;
 14         TiXmlElement* Person = rootElement->FirstChildElement();
 15         if(Person){
 16                 cout << "person exists"<<endl;
 17                 TiXmlAttribute *personAttributes = Person->FirstAttribute();
 18                 cout << personAttributes->Name()<<":"<<personAttributes->Value()<<endl;
 19         }
 20 }

 

其实就是每次申明该类对象的指针,然后,用其他的函数使指针指向下一个对象。但是如果知道xml中的某个key,要直接取value好像不行。需要遍历一次,然后比对才能拿到。

 

不过至少可以用了,而且比较简单。不错~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值