Reputation: 509
I need to parse xml string from remote URL, and I want to use AFNetworking. This is my code:
NSURL *url2 = [NSURL URLWithString:@"REMOTEXMLURL"];
NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];
AFXMLRequestOperation *operation2 = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:request2
success:^(NSURLRequest *request2, NSHTTPURLResponse *response2, NSXMLParser *XMLParser) {
NSLog(@"TESTING PARSING");
[XMLParser setDelegate:self];
[XMLParser parse];
} failure:^(NSURLRequest *request2, NSHTTPURLResponse *response2, NSError *error2, NSXMLParser *XMLParser) {
NSLog(@"%@", [error2 userInfo]);
}];
[operation2 start];
Is it correct? And now that I have *XMLParser, can I avoid to use NSXMLParser delegate methods, like:
-(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
or I'm constrained to use that? In other words, *XMLParser object initialized with AFNetworking and AFXMLRequestOperation must be passed to delegate methods, or can I parse it in another way (like AFJSONRequestOperation, into AFNetworking operation)? Thank you!
Upvotes: 0
Views: 1732
Reputation: 9902
The NSXMLParser needs a delegate. If you want to use NSXMLParser, and want your class to be its delegate, you need to implement the delegate methods to make sense of your XML.
The XML parser doesn't know what the meaning of your XML is, it just reads it to you; you have to understand it yourself.
Upvotes: 2