1

I have the following method, I have one more method through which I am calling this method, but have no luck yet.

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
    namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
    attributes:(NSDictionary *)attributeDict{

        if ([elementName isEqualToString:@"isphone-config"]) {
            Pusername = [attributeDict valueForKey:@"authentication_username"];    
            Ppassword = [attributeDict valueForKey:@"authentication_password"];
            Pidentity = [attributeDict valueForKey:@"sip_identity"];
            Pdomain   = [attributeDict valueForKey:@"domain"];
            Pprotocol = [attributeDict valueForKey:@"protocol"];
            Pudpport  = [attributeDict valueForKey:@"registrar_port"];
            Ptcpport  = [attributeDict valueForKey:@"listening_port"];

            NSLog(@"Title: %@, ID: %@", Pusername, Ppassword);
        }
    }
}

And I am calling it from the following method..

NSString* username = [[NSUserDefaults standardUserDefaults] stringForKey:@"username_preference"];
NSString* accountPassword = [[NSUserDefaults standardUserDefaults] stringForKey:@"password_preference"];
NSString* urlString = [NSString stringWithFormat:@"https://%@:%@@test.com/test.php",username,accountPassword];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

parser = [[NSXMLParser alloc] initWithData: response];

NSLog(@"at parser %@", parser);

[parser setDelegate:self];

I am having issues in the last line of the code from where I am calling parser. I assume that this line will call the method parser, correct me if I am wrong. I don't know which files, interfaces and classes I have to import, include or implement.

1 Answer 1

1

XML parsing with NSXMLParser is much more difficult, check Apple's example "earthquakes".

Instead I suggest you to use another XML parser. For example, this one:

Also, good article about how to choose parser.

http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml

Sign up to request clarification or add additional context in comments.

1 Comment

This approach is far easy than NSXMLParser... I spent a lot of time on NSXMLParser and had no luck !!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.