使用数据ios初始化NSXMLparser

时间:2012-07-19 09:30:46

标签: ios web-services initialization nsxmlparser null

大家好我什么都没有(零值)当我尝试使用从Web服务响应获得的数据初始化我的NSXMLparser时这是我使用的代码:

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

1 个答案:

答案 0 :(得分:0)

尝试这个以分配x​​ml解析器

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

}