0

こんにちは、Web サービスの応答から取得したデータで NSXMLparser を初期化しようとすると、何も取得されません (nil 値)。これは私が使用するコードです。

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];

}

リンク

4

1 に答える 1

0

xmlパーサーを割り当てるためにこれを試してください

-(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  ");
}

}

于 2012-07-19T11:49:10.833 に答える