2012-07-19 60 views
0

嗨,大家好,我得到根本不算什麼(零值),當我嘗試初始化我的NSXMLParser與我從Web服務響應中獲取數據,這是我使用的代碼:零的NSXMLParser初始化數據IOS

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

+0

// XMLPARSER = [[ALLOC的NSXMLParser] initWithData:conWebMutableData]; NSXMLParser分配評論在你的代碼請取消註釋,然後嘗試 – 2012-07-19 11:54:02

+0

「conWebMutableData」需要是初始化/分配否則它不會保留服務器響應... – 2012-07-19 13:08:04

回答

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

}

+0

我嘗試兩個註釋行初始化解析器,但我得到相同結果(零值),因爲我已經評論了兩條線,因爲我沒有得到正確的結果,並且對我來說沒有任何用處 – user1001635 2012-07-19 12:19:27

+0

ok ..不是問題..我們嘗試調試, 您可以NSLog服務器返回的響應 NSString * xmlResponseString = [[[NSString alloc] initWithData:conWebMutableData encoding:NSUTF8StringEncoding] autorelease]; NSLog(@「xmlResponseString --->%@」,xmlResponseString); 另外,它似乎沒有初始化conWebMutableData,請初始化/分配它,然後它會讓你在連接委託方法中追加值 – 2012-07-19 12:44:44

+0

我嘗試你的解決方案,但錯誤仍然存​​在,請參閱我的第一條評論中的圖像 – user1001635 2012-07-20 09:53:00