Question

Previously, I was able to get the contents of the URL with this encoding:

<?xml version = "1.0" encoding = "UTF-8"?>

And parse it into NSString with codes shown below:

NSMutableData *receivedData =  [[[NSMutableData alloc] initWithContentsOfURL:[NSURL URLWithString:authenticateURL]] autorelease];
    NSString *string = [[[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] autorelease];if (string) {   // if connection established, string will look for <error> in XML
        NSRange range = [string rangeOfString:@"<error>"];
        if (range.location == NSNotFound) {
            result = TRUE;
            NSLog(@"Authenticated!");  // if <error> not found, record is present
        }                           //return TRUE to load data
        else {
            result = FALSE;         // <error> found in XML, record is not found
            NSLog(@"Not Authenticated!");
        }
    }

However, the contents I need to fetch now is actually without a type of encoding, example:

<?xml version="1.0" ?><authenticate><auth>Y</auth></authenticate>

Therefore now, as I NSLog the string, it is empty. Have tried searching for other methods but all the examples I found, people were fine with using UTF8StringEncoding. Would be glad for any advice :)!Thanks!

Was it helpful?

Solution 4

Sorry all, actually the reason why I was unable to retrieve the XML from the URL is because of some SSL problem. The solution I used can be found here: How to use NSURLConnection to connect with SSL for an untrusted cert?

Thank you everyone for helping too^^

OTHER TIPS

You could use the open source library TBXML in combination with https://gist.github.com/1922643 to convert the received XML into an NSDictionary. It supports NSData (using NSUTF8StringEncoding) and plain NSStrings.

This NSDictionary contains all the information available in the XML and you could just read it using the objectForKey: function.

you can user NSXMLParser class

this is a good Tutorial show you hw to user this class

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top