Objective c 从xml文件创建一个数组
我的XML格式如下所示:Objective c 从xml文件创建一个数组,objective-c,soap,nsxmlparser,Objective C,Soap,Nsxmlparser,我的XML格式如下所示: <Rows> <Row> <style>String</style? <thumbnail>String</thumbnail> </Row> <Row> <style>String</style? <thumbnail>String</thumbnail> </Row> <
<Rows>
<Row>
<style>String</style?
<thumbnail>String</thumbnail>
</Row>
<Row>
<style>String</style?
<thumbnail>String</thumbnail>
</Row>
</Rows>
我弄错了格式如果我这样做请帮帮我
提前感谢。创建一个对象类,比如SampleObj *SampleObj.h*
@interface SampleObj : NSObject
{
NSString *style;
NSString *thumbnail;
}
@property (nonatomic,retain) NSString *style,*thumbnail;
@implementation SampleObj
@synthesize style,thumbnail;
//dealloc your synthesized value;
*SampleObj.m*
@interface SampleObj : NSObject
{
NSString *style;
NSString *thumbnail;
}
@property (nonatomic,retain) NSString *style,*thumbnail;
@implementation SampleObj
@synthesize style,thumbnail;
//dealloc your synthesized value;
像这样做
NSArray *array=[theXML componentsSeparatedByString:@"<Rows>"];
for(int i=1;i<[array count];i++)
{
NSArray *arrayRow=[theXML componentsSeparatedByString:@"<Row>"];
for(int j=1;j<[arrayRow count];j++)
{
SampleObj *custobj = [[SampleObj alloc] init];
NSString *str=[arrayRow objectAtIndex:i];
NSArray *arr1=[str componentsSeparatedByString:@"<style>"];
NSString *data=[arr1 objectAtIndex:1];
NSRange ranfrom=[data rangeOfString:@"</style>"];
custobj.style =[data substringToIndex:ranfrom.location];
arr1=[str componentsSeparatedByString:@"< thumbnail >"];
data=[arr1 objectAtIndex:1];
ranfrom=[data rangeOfString:@"</thumbnail >"];
custobj.thumbnail=[data substringToIndex:ranfrom.location];
[yourarray addObject:custobj];
[custobj release]
}
}
希望这会有帮助。对不起,有错