加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

TBXML解析的XML

发布时间:2020-12-15 22:47:09 所属栏目:百科 来源:网络整理
导读:TBXML下载地址:https://github.com/71squared/TBXML 这是我解析的XML(setting.xml),做个备忘 root setting title EventOn /title layout tile /title headerStyle Banner /headerStyle color 颜色值 /color date 2013-02-13 /date location 位置 /location /
TBXML下载地址:https://github.com/71squared/TBXML

这是我解析的XML(setting.xml),做个备忘

<root>

<setting>

<title>EventOn</title>

<layout>tile</title>

<headerStyle>Banner</headerStyle>

<color>颜色值</color>

<date>2013-02-13</date>

<location>位置</location>

</setting>

<!--主菜单 -->

<moduleid="mainmenu"title="首页sdfsdfsd"icon="custom_icon.png">

<item="地图ssfdafs"="close"target="EOMapViewController"/>

="标题2"="ItemViewController"="标题3"="itemImage"/>

</module>

<moduleid="map"title"地图"locationName豪成大厦3A02"latitude""longitude>

</module>

</root>


TBXML.hTBXML.m
放到工程里就OK了

#import"TBXML.h"

@interfaceXXXClass :NSObject<NSXMLParserDelegate>


加入委托代理NSXMLParserDelegate


加载setting.xml

NSError*error;

TBXML*tbxml = [TBXMLnewTBXMLWithXMLFile:@"setting.xml"error:&error];

TBXMLElement*rootElement = tbxml.rootXMLElement;

if(error) {

NSLog(@"%@ %@",[errorlocalizedDescription],[erroruserInfo]);

}else{

TBXMLElement*element = [childElementNamed:@"module"parentElement:rootElement];

[selfdealMoudle:element];

}


解析module结点信息


- (void) dealMoudle:(TBXMLElement*)element{

do{

NSString*value = [valueOfAttributeNamed:@"id"forElement:element];

if([valueisEqualToString:@"mainmenu"]){

[dealMainMenuMoudle:element];

}

@"map"]){

}

}while((element = element->nextSibling));

}

- (void) dealMainMenuMoudle:(TBXMLElement*)_element{

@"item"parentElement:_element];

self.mainMenuArray= [[NSMutableArrayalloc]init];

self.mainMenuTitle= [TBXMLvalueOfAttributeNamed:@"title"forElement:_element];

do{

NSMutableDictionary*item = [[NSMutableDictionaryalloc]init];

[itemsetObject:[@"title"forElement:element]forKey:@"title"];

[item@"icon"@"icon"];

[item@"target"@"target"];

[mainMenuArrayaddObject:item];

}nextSibling));

}

好了,代码暂时就这么多,做个记录

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读