开发者

iphone xml parsing issue

I am trying to get XML parsing done for my iphone app. But am stuck with an error:

XMLParser *xParser = [[XMLParser alloc] initWithContentsofURL:@" http://myimgurl.com/iphoneappimages.xml";];

[xParser setParseItem:@"image"];

[xParser startParse]; 

NSArray *arrItems = [xParser objectForKey:@"image"];

Getting the error - 'XMLParser' ma开发者_JAVA技巧y not respond to '-objectForKey:' - on the last line.

What is wrong here?

Thanks.


From apple's class reference:

An NSXMLParser notifies its delegate about the items (elements, attributes, CDATA blocks, comments, and so on) that it encounters as it processes an XML document. It does not itself do anything with those parsed items except report them.

You need to make your class an NSXMLParserDelegate and use these (and other) delegate methods:

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜