TBXML解析的XML

前端之家收集整理的这篇文章主要介绍了TBXML解析的XML前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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));

}

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

猜你在找的XML相关文章