2014-11-05 4 views
0

난 다음 아이폰 OS - 구문 분석 XML 데이터 세트

<DataTable xmlns="http://tempuri.org/“> 

<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-  microsoft-com:xml-diffgram-v1"> 
<NewDataSet xmlns=“"> 

<Products diffgr:id="Products1" msdata:rowOrder="0"> 
<ItemCode>001G1-R25111-1701</ItemCode> 
<ItemName>Autocad 2015</ItemName> 
<Price>160714.000000</Price> 
</Products> 
<Products diffgr:id="Products2" msdata:rowOrder="1"> 
<ItemCode>011-0656</ItemCode> 
<ItemName>"SVC, HARDWARE TEST 1"</ItemName> 
<Price>0.000000</Price> 
</Products> 
<Products diffgr:id="Products3" msdata:rowOrder="2"> 
<ItemCode>011-0657</ItemCode> 
<ItemName>"SVC, HARDWARE TEST 2"</ItemName> 
<Price>0.000000</Price> 
</Products> 

</NewDataSet> 
</diffgr:diffgram> 
</DataTable> 

This is my view.h 
#import <Foundation/Foundation.h> 

@interface view : NSObject 
{ 
int *itemcode; 
NSString *itemname; 
NSString *price; 
} 


@property (nonatomic, assign) int *itemcode; 
@property (nonatomic, retain) NSString *itemname; 
@property (nonatomic, retain) NSString *price; 
@end 

view.m 

#import "view.h" 

@implementation view 
@synthesize itemcode,itemname,price; 

@end 

데이터를 구문 분석하는 데 사용하여 코드 메신저입니다 구문 분석 할 내 XML 데이터 :

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName 
attributes: (NSDictionary *)attributeDict 
{ 
if([elementName isEqualToString:@"DataTable"]) 
{ 
    if(!soapResults) 
     soapResults = [[NSMutableString alloc] init]; 
    recordResults = TRUE; 
} 

if([elementName isEqualToString:@"NewDataSet"]) { 

    messages = [[NSMutableArray alloc] init]; 
} 
else if([elementName isEqualToString:@"Products"]) { 

    aMessage = [[view alloc] init]; 
} 
} 
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 
{ 
if(recordResults) 
    [soapResults appendString: string]; 

} 
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString  *)namespaceURI qualifiedName:(NSString *)qName 
{ 

if([elementName isEqualToString:@"Products"]) { 

    [messages addObject:aMessage]; 

    [aMessage setValue: soapResults forKey:elementName]; 
    NSLog(@"MESSAGES COUNT: %d",messages.count); 
    NSLog(@"MESSAGE: %@",aMessage); 

    aMessage = nil; 
} 
// as this is the last element 
if([elementName isEqualToString:@"NewDataSet"]) 
{ 
    recordResults = FALSE; 
} 
} 

임 구문 분석 된 데이터를받지 못하고 있으며 충돌한다 에서. 'NSUnknownKeyException', 이유 : '[setValue : forUndefinedKey :] :이 클래스는 키 ItemCode에 대해 키 값 코딩을 준수하지 않습니다.'

답변

0

view.h 파일에서 U는 변수 태그 이름 같아야

int * ItemCode; 
NSString * ItemName; 
NSString * Price; 

같은 변수를 선언한다