parserDidEndDocument 没有被调用
parserDidNotEndDocument 没有被调用,它昨天还在工作,我认为唯一不同的是我现在使用的是 xcode 4。抛出的错误是 XML 解析错误:操作无法完成。 (NSXMLParserErrorDomain 错误 5。)
@implementation profileViewController
@synthesize userArray;
@synthesize userData;
@synthesize userId;
@synthesize gender;
@synthesize nameIB;
@synthesize numberIB;
@synthesize loginButton;
@synthesize logoutButton;
@synthesize activityIndicator;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
-(IBAction)textDone:(id)sender
{
[sender resignFirstResponder];
}
-(IBAction)genderSelection:(id)sender
{
if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
{
gender = @"Male";
//NSLog(gender);
}
else {
gender = @"Female";
//NSLog(gender);
}
}
-(IBAction)postData:(id)sender
{
loginButton.hidden = YES;
loginButton.enabled = NO;
if(nameIB.text.length && numberIB.text.length > 0)
{
//[self performSelectorInBackground:@selector(sendData) withObject:nil];
NSMutableData *data = [NSMutableData data];
NSString *number = numberIB.text;
NSString *name = nameIB.text;
NSString *nameString = [[NSString alloc] initWithFormat:@"name=%@", name];
NSString *numberString = [[NSString alloc] initWithFormat:@"&number=%@", number];
NSString *genderString = [[NSString alloc] initWithFormat:@"&gender=%@", gender];
//NSLog(nameString);
//NSLog(numberString);
[data appendData:[nameString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[numberString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[genderString dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:@"http://www.blah.net/test.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
userData = responseData;
logoutButton.hidden = NO;
logoutButton.enabled = YES;
[self startParsingUserId];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Text Fields Empty" message:@"One Or More Textfields Are Empty" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
loginButton.enabled = YES;
loginButton.hidden = NO;
logoutButton.enabled = NO;
}
}
/*-(void)sendData
{
[activityIndicator startAnimating];
NSMutableData *data = [NSMutableData data];
NSString *number = numberIB.text;
NSString *name = nameIB.text;
NSString *nameString = [[NSString alloc] initWithFormat:@"name=%@", name];
NSString *numberString = [[NSString alloc] initWithFormat:@"&number=%@", number];
NSString *genderString = [[NSString alloc] initWithFormat:@"&gender=%@", gender];
//NSLog(nameString);
//NSLog(numberString);
[data appendData:[nameString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[numberString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[genderString dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:@"http://www.blah.net/test.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
userData = responseData;
}*/
-(IBAction)logout:(id)sender
{
NSString *userID = self.userId;
NSMutableData *data = [NSMutableData data];
NSMutableString *userString = [[NSMutableString alloc] initWithFormat:@"id=%@", userID];
//NSLog(userString);
//NSLog(numberString);
[data appendData:[userString dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:@"http://www.blah.net/offline.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
loginButton.hidden = NO;
logoutButton.hidden = YES;
loginButton.enabled = YES;
logoutButton.enabled = NO;
}
-(void)startParsingUserId
{
NSLog(@"parsing init");
NSXMLParser *idParser = [[NSXMLParser alloc] initWithData:userData]; //uses the NSMutableData data type to parse
idParser.delegate = self; //set the delegate to this viewControlelr
[idParser parse];
[idParser release];
}
-(void)parserDidStartDocument:(NSXMLParser *)parser
{
NSLog(@"parsing started");
currentElementName = nil;
currentText = nil;
}
//this is called for each xml element
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
//NSLog(@"started element");
if ([elementName isEqualToString:@"usercallback"]) //if elementName == status then start of new tweet so make new dictionary
{
[currentIDDict release];
currentIDDict = [[NSMutableDictionary alloc] initWithCapacity:[interestingTags count]]; //make dictionary with two sections
}
else if([interestingTags containsObject:elementName]) //if current element is one stored in interesting tag, hold onto the elementName and make a new string to hold its value
{
currentElementName = elementName; //hold onto current element name
currentText = [[NSMutableString alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog(@"appending");
[currentText appendString:string];
}
//after each element it goes back to the parent after calling this method
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:currentElementName])
{
[currentIDDict setValue: currentText forKey: currentElementName];
}
else if([elementName isEqualToString:@"usercallback"])
{
[self.userArray addObject:currentIDDict];
}
NSLog(@"ending");
currentText = nil;
[currentText release];
}
-(void)parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(@"end");
NSDictionary *rowData = [self.userArray objectAtIndex:0];
userId = [[NSString alloc] initWithFormat:@"%@", [rowData objectForKey:@"id"]];
NSLog(@"DONE PARSING DOCUMENT");
NSLog(@"userid = %@", userId);
}
parserDidNotEndDocument does not get called, it was working yesterday, the only thing that i think is different is i am using xcode 4 now. error getting thrown is Error on XML Parse: The operation couldn’t be completed. (NSXMLParserErrorDomain error 5.)
@implementation profileViewController
@synthesize userArray;
@synthesize userData;
@synthesize userId;
@synthesize gender;
@synthesize nameIB;
@synthesize numberIB;
@synthesize loginButton;
@synthesize logoutButton;
@synthesize activityIndicator;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
-(IBAction)textDone:(id)sender
{
[sender resignFirstResponder];
}
-(IBAction)genderSelection:(id)sender
{
if([sender selectedSegmentIndex] == kSwitchesSegmentIndex)
{
gender = @"Male";
//NSLog(gender);
}
else {
gender = @"Female";
//NSLog(gender);
}
}
-(IBAction)postData:(id)sender
{
loginButton.hidden = YES;
loginButton.enabled = NO;
if(nameIB.text.length && numberIB.text.length > 0)
{
//[self performSelectorInBackground:@selector(sendData) withObject:nil];
NSMutableData *data = [NSMutableData data];
NSString *number = numberIB.text;
NSString *name = nameIB.text;
NSString *nameString = [[NSString alloc] initWithFormat:@"name=%@", name];
NSString *numberString = [[NSString alloc] initWithFormat:@"&number=%@", number];
NSString *genderString = [[NSString alloc] initWithFormat:@"&gender=%@", gender];
//NSLog(nameString);
//NSLog(numberString);
[data appendData:[nameString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[numberString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[genderString dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:@"http://www.blah.net/test.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
userData = responseData;
logoutButton.hidden = NO;
logoutButton.enabled = YES;
[self startParsingUserId];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Text Fields Empty" message:@"One Or More Textfields Are Empty" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
loginButton.enabled = YES;
loginButton.hidden = NO;
logoutButton.enabled = NO;
}
}
/*-(void)sendData
{
[activityIndicator startAnimating];
NSMutableData *data = [NSMutableData data];
NSString *number = numberIB.text;
NSString *name = nameIB.text;
NSString *nameString = [[NSString alloc] initWithFormat:@"name=%@", name];
NSString *numberString = [[NSString alloc] initWithFormat:@"&number=%@", number];
NSString *genderString = [[NSString alloc] initWithFormat:@"&gender=%@", gender];
//NSLog(nameString);
//NSLog(numberString);
[data appendData:[nameString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[numberString dataUsingEncoding:NSUTF8StringEncoding]];
[data appendData:[genderString dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:@"http://www.blah.net/test.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
userData = responseData;
}*/
-(IBAction)logout:(id)sender
{
NSString *userID = self.userId;
NSMutableData *data = [NSMutableData data];
NSMutableString *userString = [[NSMutableString alloc] initWithFormat:@"id=%@", userID];
//NSLog(userString);
//NSLog(numberString);
[data appendData:[userString dataUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:@"http://www.blah.net/offline.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:data];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
loginButton.hidden = NO;
logoutButton.hidden = YES;
loginButton.enabled = YES;
logoutButton.enabled = NO;
}
-(void)startParsingUserId
{
NSLog(@"parsing init");
NSXMLParser *idParser = [[NSXMLParser alloc] initWithData:userData]; //uses the NSMutableData data type to parse
idParser.delegate = self; //set the delegate to this viewControlelr
[idParser parse];
[idParser release];
}
-(void)parserDidStartDocument:(NSXMLParser *)parser
{
NSLog(@"parsing started");
currentElementName = nil;
currentText = nil;
}
//this is called for each xml element
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
//NSLog(@"started element");
if ([elementName isEqualToString:@"usercallback"]) //if elementName == status then start of new tweet so make new dictionary
{
[currentIDDict release];
currentIDDict = [[NSMutableDictionary alloc] initWithCapacity:[interestingTags count]]; //make dictionary with two sections
}
else if([interestingTags containsObject:elementName]) //if current element is one stored in interesting tag, hold onto the elementName and make a new string to hold its value
{
currentElementName = elementName; //hold onto current element name
currentText = [[NSMutableString alloc] init];
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSLog(@"appending");
[currentText appendString:string];
}
//after each element it goes back to the parent after calling this method
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:currentElementName])
{
[currentIDDict setValue: currentText forKey: currentElementName];
}
else if([elementName isEqualToString:@"usercallback"])
{
[self.userArray addObject:currentIDDict];
}
NSLog(@"ending");
currentText = nil;
[currentText release];
}
-(void)parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(@"end");
NSDictionary *rowData = [self.userArray objectAtIndex:0];
userId = [[NSString alloc] initWithFormat:@"%@", [rowData objectForKey:@"id"]];
NSLog(@"DONE PARSING DOCUMENT");
NSLog(@"userid = %@", userId);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现解析错误的解决方案:
Solution for finding parse error: