TBXML解析的XML
TBXML下载地址: https://github.com/71squared/TBXML这是我解析的XML(setting.xml),做个备忘EventOntileBanner颜色值2013-02-13位置主菜单 -->id="mainmenu" title="首页sdfsdfsd"
<root>
<setting>
<title>EventOn</title>
<layout>tile</title>
<headerStyle>Banner</headerStyle>
<color>颜色值</color>
<date>2013-02-13</date>
<location>位置</location>
</setting>
<!-- 主菜单 -->
<module id="mainmenu" title="首页sdfsdfsd" icon="custom_icon.png">
<item title="地图ssfdafs" icon="close" target="EOMapViewController"/>
<item title="标题2" icon="close" target="ItemViewController"/>
<item title="标题3" icon="itemImage" target="ItemViewController"/>
</module>
<module id="map" title="地图" locationName="豪成大厦3A02" latitude="" longitude="">
</module>
</root>
#import "TBXML.h"
@interface XXXClass : NSObject <NSXMLParserDelegate>
加入委托代理NSXMLParserDelegate
加载setting.xml
NSError *error;
TBXML *tbxml = [TBXML newTBXMLWithXMLFile:@"setting.xml" error:&error];
TBXMLElement *rootElement = tbxml.rootXMLElement;
if (error) {
NSLog(@"%@ %@", [error localizedDescription], [error userInfo]);
} else {
TBXMLElement *element = [TBXML childElementNamed:@"module" parentElement:rootElement];
[self dealMoudle:element];
}
解析module结点信息
- (void) dealMoudle:(TBXMLElement *)element{
do{
NSString *value = [TBXML valueOfAttributeNamed:@"id" forElement:element];
if([value isEqualToString:@"mainmenu"]){
[self dealMainMenuMoudle:element];
}
if([value isEqualToString:@"map"]){
}
}while ((element = element->nextSibling));
}
- (void) dealMainMenuMoudle:(TBXMLElement *)_element{
TBXMLElement *element = [TBXML childElementNamed:@"item" parentElement:_element];
self.mainMenuArray = [[NSMutableArray alloc] init];
self.mainMenuTitle = [TBXML valueOfAttributeNamed:@"title" forElement:_element];
do{
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
[item setObject:[TBXML valueOfAttributeNamed:@"title" forElement:element] forKey:@"title"];
[item setObject:[TBXML valueOfAttributeNamed:@"icon" forElement:element] forKey:@"icon"];
[item setObject:[TBXML valueOfAttributeNamed:@"target" forElement:element] forKey:@"target"];
[self.mainMenuArray addObject:item];
}while((element = element->nextSibling));
}
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)