0

Im practicing RESTKit, and so I'm building a Dribbble client to get the hang of REST, i get the XML response successfully, but when i use NSXMLParser to parse it, it logs start, then stop immediately after, how can i fix it, or just make it easier with the XML to sort out which item is which, and put it into my table then?

heres the code:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
    NSLog(@"I just found a start tag for %@",elementName);

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
    NSLog(@"the parser just found this text in a tag:%@",string);
}

-(void)parserDidStartDocument:(NSXMLParser *)parser {
    NSLog(@"starting");
}

-(void)parserDidEndDocument:(NSXMLParser *)parser {
    NSLog(@"end");
}

-(IBAction)test {
    [[RKClient sharedClient] get:@"/shots/popular" delegate:self];
}

-(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
    if ([request isGET]) {

        NSLog(@"Retrieved XML: %@", [response bodyAsString]);
        NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[response body]];
        [xmlParser setDelegate:self];
        [xmlParser parse];
    }
    else if ([request isPOST]) {


        if ([response isJSON]) {

            NSLog(@"Got a JSON response back from our POST!");
        }


    }
    else if ([request isDELETE]) {

        if ([response isNotFound]) {
            NSLog(@"The resource path '%@' was not found.", [request resourcePath]);
        }


    }
}
Maximilian Litteral
  • 3,059
  • 2
  • 31
  • 41
  • Sounds like there may be an error. You should implement `parser:parseErrorOccurred:` and see what it says. – jscs Jul 01 '12 at 23:45
  • i NSLogged it, i got "error occured: Error Domain=NSXMLParserErrorDomain Code=4 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)"", how do i fix then, don't really know a lot on NSXMLParser. – Maximilian Litteral Jul 02 '12 at 00:03

1 Answers1

0

The error you're getting from the parser is NSXMLParserEmptyDocumentError. It seems that you're not getting the response that you expect from the server; this isn't a problem with the parser.

You should check that no error occurs with the connection or response, and that the result is actually an XML document.

jscs
  • 63,694
  • 13
  • 151
  • 195
  • in the code, i log it, NSLog(@"Retrieved XML: %@", [response bodyAsString]); and it has the xml, and i see the info i need, so then i use NSXMLParser with the body, and body should be the data same as the string, just not string. NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:[response body]] and the bodyAsString isn't null so shouldn't body not be empty? – Maximilian Litteral Jul 02 '12 at 01:46