在XCODE中解析受保护的XML

时间:2012-05-14 01:51:11

标签: xml xcode nsurlconnection nsconnection

我想知道是否有人可以帮助解析XCODE中受保护的XML文件。

这是我得到的,但我不知道如何混淆这些东西,因为我在XCODE中很新。

与身份验证连接

    -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:    (NSURLAuthenticationChallenge *)challenge
{   
if ([challenge previousFailureCount] == 0) {
    NSURLCredential *newCredential;
    newCredential=[NSURLCredential credentialWithUser:@"myusername"
                                             password:@"mypassword"
                                          persistence:NSURLCredentialPersistenceNone];
    [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
} else {
    [[challenge sender] cancelAuthenticationChallenge:challenge];
    NSLog(@"Bad Username Or Password");

    UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Authentication Error" message:@"Unable to connect to the server, Please Contact The WebMaster." delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
    [aler show];
    [aler release]; 
}
    }

解析代码

    -(void)doParse
{
[SongArray removeAllObjects];
//NEED TO GET XML DOCUMENT INTO NSData OBJECT!!!
NSURL *theURL = [[NSURL alloc] initWithString:@"myurl"];
// create and init NSXMLParser object



NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:theURL];
// create and init our delegate
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//set delegate
[nsXmlParser setDelegate:parser];
//parsing...
BOOL success = [nsXmlParser parse];
// test the result
if (success) {
    NSLog(@"success");
    SongArray = [parser getPeople];
    [self.SongDescription reloadData];

} else {

    UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Server Error" message:@"Unable To Read The Song Information, You May Keep Listening To The Radio Without Song Information" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
    [aler show];
    [aler release];

    NSLog(@"fail");
}

    }

0 个答案:

没有答案