このようなデータを解析しています。
parserSignIn = [[NSXMLParser alloc]initWithData:_responseData];
[parserSignIn setDelegate:self];
[parserSignIn parse];
その後
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
tagName = [[NSString alloc] initWithString:elementName];
if (parser == parserSignIn) {
if ([tagName isEqualToString:@"MemberDetail"]) {
NSLog(@"value is %@", elementName);
NSManagedObjectContext *managedObjectContext = [database managedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"MemberDetails" inManagedObjectContext:managedObjectContext];
memberDetails = [[MemberDetails alloc] initWithEntity:entityDescription insertIntoManagedObjectContext:managedObjectContext];
}
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"FOUND %@", string);
if ([tagName isEqualToString:@"InvalidLogin"]) {
isSignIn = NO;
}else{
NSLog(@"NOT INVALID");
isSignIn = YES;
if ([tagName isEqualToString:@"MemberId"]) {
memberDetails.memberId = string;
}else if ([tagName isEqualToString:@"FirstName"]){
memberDetails.firstname = string;
}else if ([tagName isEqualToString:@"LastName"]){
memberDetails.lastname = string;
}
else if ([tagName isEqualToString:@"Email"]){
memberDetails.email = string;
}
NSLog(@"DATA is %@", memberDetails);
}
}
MemberDetails.h の場所
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface MemberDetails : NSManagedObject
@property (nonatomic, retain) NSString * memberId;
@property (nonatomic, retain) NSString * firstname;
@property (nonatomic, retain) NSString * lastname;
@property (nonatomic, retain) NSString * email;
MemberDetails.m is
@dynamic memberId;
@dynamic firstname;
@dynamic lastname;
@dynamic email;
NSLog を MemberDetails オブジェクトに使用して、データを出力します。
0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = nil;
firstname = nil;
lastname = nil;
memberId = nil;
})
2013-09-15 16:10:33.540 ECP[24094:c07] FOUND 10758
2013-09-15 16:10:33.541 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.541 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = nil;
firstname = nil;
lastname = nil;
memberId = 10758;
})
2013-09-15 16:10:33.543 ECP[24094:c07] FOUND
2013-09-15 16:10:33.543 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.544 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = nil;
firstname = nil;
lastname = nil;
memberId = "\n ";
})
2013-09-15 16:10:33.544 ECP[24094:c07] FOUND Amit
2013-09-15 16:10:33.545 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.545 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = nil;
firstname = Duaan;
lastname = nil;
memberId = "\n ";
})
2013-09-15 16:10:33.545 ECP[24094:c07] FOUND
2013-09-15 16:10:33.545 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.546 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = nil;
firstname = "\n ";
lastname = nil;
memberId = "\n ";
})
2013-09-15 16:10:33.548 ECP[24094:c07] FOUND Metha
2013-09-15 16:10:33.548 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.548 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = nil;
firstname = "\n ";
lastname = Rajput;
memberId = "\n ";
})
2013-09-15 16:10:33.548 ECP[24094:c07] FOUND
2013-09-15 16:10:33.549 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.549 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = nil;
firstname = "\n ";
lastname = "\n ";
memberId = "\n ";
})
2013-09-15 16:10:33.549 ECP[24094:c07] FOUND amit@sevdotcom.ae
2013-09-15 16:10:33.550 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.550 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = "duan@abccompany.ae";
firstname = "\n ";
lastname = "\n ";
memberId = "\n ";
})
2013-09-15 16:10:33.556 ECP[24094:c07] FOUND
2013-09-15 16:10:33.557 ECP[24094:c07] NOT INVALID
2013-09-15 16:10:33.557 ECP[24094:c07] DATA is <MemberDetails: 0x9533320> (entity: MemberDetails; id: 0x9533360 <x-coredata:///MemberDetails/tD0F9345D-847F-4E6A-9C2F-22F4A23CB1B02> ; data: {
email = "\n";
firstname = "\n ";
lastname = "\n ";
memberId = "\n ";
})
データを保存してオブジェクトを印刷しているときに、なぜnilを実行するのですか? xmlの一部ではない\nが保存されているのは何ですか?
ありがとう