2011-06-18 11 views
1

parserDidNotEndDocumentが呼び出されない、それは昨日働いていた、私は異なっていると思う唯一のことは、今私はxcode 4を使用しています。スローされるエラーはXML Parseでエラーです:操作を完了できませんでした。 (NSXMLParserErrorDomainエラー5)パースエラーを見つけるためのparserDidEndDocumentが呼び出されない

@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); 

} 
+3

は問題がXMLファイルの内容であるかもしれません。 ' - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError'メソッドを実装し、呼び出されるかどうかを調べてみてください。 – Jiri

+1

XML Parseでエラーが発生しました:操作を完了できませんでした。 (NSXMLParserErrorDomain error 5.) – mintuz

+0

本当にあなたのコメントを助けました - ) –

答えて

1

ソリューション:

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError 
{ 
    NSDictionary *userInfo = parseError.userInfo; 
    NSNumber *lineNumber = userInfo[@"NSXMLParserErrorLineNumber"]; 
    NSNumber *errorColumn = userInfo[@"NSXMLParserErrorColumn"]; 
    NSString *errorMessage = userInfo[@"NSXMLParserErrorMessage"]; 

    NSLog(@"Error occured in line %@ and column %@\nWith message: %@", lineNumber, errorColumn, errorMessage); 
} 
関連する問題