Мой XMLParser ниже
//
// yFrogParser.h
// PreviewMaker
//
// Created by Anthony Cornell on 4/12/12.
// Copyright (c) 2012 iDevice Designs. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "yFrogObject.h"
@interface yFrogParser : NSObject<NSXMLParserDelegate>{
NSMutableData *recivedData;
NSMutableArray *imageInfo;
NSMutableString *currentNodeContent;
NSXMLParser *parser;
yFrogObject *imageObjects;
NSMutableArray *imageArray;
}
@property (readonly, retain) NSMutableArray *imageInfo;
@property (nonatomic, retain) NSMutableArray *imageArray;
@property (nonatomic, retain) NSMutableData *recivedData;
-(id) loadXMLByData:(NSMutableData *)data;
@end
//
// yFrogParser.m
// PreviewMaker
//
// Created by Anthony Cornell on 4/12/12.
// Copyright (c) 2012 iDevice Designs. All rights reserved.
//
#import "yFrogParser.h"
@implementation yFrogParser
@synthesize imageInfo,imageArray,recivedData;
-(id) loadXMLByData:(NSMutableData *)data{
imageArray = [[NSMutableArray alloc] init];
recivedData = [[NSMutableData alloc]initWithData:data];
parser = [[NSXMLParser alloc] initWithData:recivedData];
parser.delegate = self;
[parser parse];
return self;
}
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:@"links"])
{
imageObjects = [yFrogObject alloc];
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"image_link"]) {
imageObjects.responceURL = currentNodeContent;
}
if ([elementName isEqualToString:@"image_bb"]) {
imageObjects.forumUrl = currentNodeContent;
// NSLog(@"image forum url %@",currentNodeContent);
}
if ([elementName isEqualToString:@"links"])
{
[imageArray addObject:imageObjects];
[imageObjects release];
imageObjects = nil;
[currentNodeContent release];
currentNodeContent = nil;
}
}
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string
stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];
}
@end
В вашем делегате сделайте что-нибудь подобное
-(void) connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
parser = [[yFrogParser alloc]init];
[parser loadXMLByData:webData];
yFrogObject *object = [[parser imageArray]objectAtIndex:0];
NSString* responseString = [[NSString alloc] initWithData:webData
encoding:NSUTF8StringEncoding];
//NSLog(@"Parser result: %@", [object responceURL]);
//NSLog(@"yFrog responce results: %@", responseString);
[responseString release];
}
В настроении делиться! Надеюсь, это поможет