2011-02-10 110 views
0

我想爲我的iphone應用程序完成XML解析。但我堅持了一個錯誤:iphone xml解析問題

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

[xParser setParseItem:@"image"]; 

[xParser startParse]; 

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

得到的錯誤 - 'XMLParser' may not respond to '-objectForKey:' - 在最後一行。

這裏有什麼問題?

謝謝。

+0

什麼是XMLParser的課? – Vladimir 2011-02-10 10:30:27

回答

1

從蘋果公司的類參考:

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.

你需要讓你的類的NSXMLParserDelegate並使用這些(和其他)的委託方法:

- (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