0

hi guys i get simply nothing (nil value) when i try to initialize my NSXMLparser with data that i get from web service response this is the code i use:

header.h

NSData*abccc;
NSMutableData*conWebMutableData;
NSXMLParser*xmlParser;

@interface ResponseWebServices_View : UIViewController<NSStreamDelegate,   NSXMLParserDelegate>


@property(nonatomic,strong)NSMutableString*soapResults;
@property(nonatomic,strong)NSXMLParser*xmlParser;
@property(nonatomic, strong)NSData*abcc;

@end

file.m

-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response{
[conWebMutableData setLength:0];

}

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data{
[conWebMutableData appendData:data];

}
-(void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error{
NSLog(@"ERROR with con");

}
-(void)connectionDidFinishLoading:(NSURLConnection*)connection{

NSString*theXML = [[NSString alloc]initWithBytes: [conWebMutableData mutableBytes]   length:[conWebMutableData length]encoding:NSUTF8StringEncoding];
NSLog(theXML);
abccc= [theXML dataUsingEncoding:NSUTF8StringEncoding];
//xmlParser = [[NSXMLParser alloc]initWithData:conWebMutableData]; (0x00000000)xmlParser value i get
//xmlParser = [[NSXMLParser alloc]initWithData:abccc]; (0x00000000)xmlParser value 
[xmlParser setDelegate:self ];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];

}

a link

Community
  • 1
  • 1
user1001635
  • 3,262
  • 3
  • 16
  • 17
  • //xmlParser = [[NSXMLParser alloc]initWithData:conWebMutableData]; NSXMLParser allocation is commented in ur code please uncomment and try then – iOS Test Jul 19 '12 at 11:54
  • "conWebMutableData" need to be init/alloc otherwise it will not retain the server response... – iOS Test Jul 19 '12 at 13:08

1 Answers1

0

try this for allocating xml parser

-(void)connectionDidFinishLoading:(NSURLConnection*)connection{

NSString *xmlResponseString = [[[NSString alloc] initWithData:conWebMutableData encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"xmlResponseString--->%@",xmlResponseString);

if([conWebMutableData length]>0)
{
xmlParser = [[NSXMLParser alloc]initWithData:conWebMutableData]; 
[xmlParser setDelegate:self ];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
}
else
{
Nslog("either server not send response or conWebMutableData   is empty  ");
}

}

iOS Test
  • 1,103
  • 1
  • 11
  • 18
  • i try both commented lines for initialize the parser but i get the same result (nil value), for this i have commented both lines because i don't get the right result and there are useless for me – user1001635 Jul 19 '12 at 12:19
  • ok.. not an issue.. we try to debug, Could you NSLog the server returned response NSString *xmlResponseString = [[[NSString alloc] initWithData: conWebMutableData encoding:NSUTF8StringEncoding] autorelease]; NSLog(@"xmlResponseString--->%@",xmlResponseString); Also it seems that you did not initialize to conWebMutableData, please initialize/alloc it then it will let u append values in connection delegate methods – iOS Test Jul 19 '12 at 12:44
  • i try your solution but the error is still here, see image in my first comment – user1001635 Jul 20 '12 at 09:53
  • I think u r going in right direction: as per image posted by u, I am able to see the server result (right side in bottom of the image) now put some log in xmlparser delegate methods for making sure is parsing starts. Like: NSLog(@"inside parser did start method"); – iOS Test Jul 20 '12 at 11:20
  • i already try this, i have setted the breakpoint at line 322 but it is never reached by the flow of execution, the parser never start – user1001635 Jul 20 '12 at 12:21