// // DenglXMLParser.h // #import <Foundation/Foundation.h> @interface DenglXMLParser : NSXMLParser<NSXMLParserDelegate> @property (nonatomic,strong) NSMutableArray *array; @end
// // DenglXMLParser.m // #import "DenglXMLParser.h" @interface DenglXMLParser () @end @implementation DenglXMLParser #pragma mark - <NSXMLParserDelegate> /** * 解析到某个元素的结尾 */ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { // NSLog(@"didEndElement - %@", elementName); } /** * 解析到某个元素的开头 */ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { // NSLog(@"%@---%@",elementName,attributeDict); if ([elementName isEqualToString:@"item"]) { [self.array addObject:attributeDict]; } } /** * 开始解析XML文档 */ - (void)parserDidStartDocument:(NSXMLParser *)parser { // NSLog(@"parserDidStartDocument"); self.array = [NSMutableArray array]; } /** * 解析完毕 */ - (void)parserDidEndDocument:(NSXMLParser *)parser { // NSLog(@"parserDidEndDocument"); } @end
时间: 2024-10-11 10:32:34