Reading in XML with iso-8859-1 encoding?
I've got a web based xml file in iso-8859-1 encoding that I'm trying to read into an NSXMLDocument. I've got the following code, but I can't seem to make it work? (I've tried all manner of combinations) //create the url NSString *urlString = [NSString stringWithFormat: @http://www.willowtreecrafts.co.uk/ag/ sesbuddyimport.php]; NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; //fetch the xml response NSData *urlData; NSURLResponse *response; NSError *error; urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:response error:error]; if (!urlData){ NSAlert *alert=[NSAlert alertWithError:error]; [alert runModal]; return; } //parse the xml response [doc release]; [doc setCharacterEncoding:@iso-8859-1]; //NSString *xmlstring = [NSString stringWithContentsOfURL:url usedEncoding:@iso-8859-1 error:error]; doc=[[NSXMLDocument alloc]initWithData:urlData options:0 error:error ]; //doc=[[NSXMLDocument alloc]initWithContentsOfURL:url options:0 error:error]; //doc=[[NSXMLDocument alloc]initWithXMLString:xmlstring options:0 error:error]; I get an error telling me that the input is not in UTF-8 encoding. I know the input isn't UTF-8, but how can I get it to accept the iso-8859-1 file? Thanks ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Reading in XML with iso-8859-1 encoding?
On Dec 6, 2008, at 4:35 AM, Amy Gibbs wrote: I've got a web based xml file in iso-8859-1 encoding that I'm trying to read into an NSXMLDocument. I've got the following code, but I can't seem to make it work? (I've tried all manner of combinations) //create the url NSString *urlString = [NSString stringWithFormat: @http://www.willowtreecrafts.co.uk/ag/ sesbuddyimport.php]; NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; //fetch the xml response NSData *urlData; NSURLResponse *response; NSError *error; urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:response error:error]; if (!urlData){ NSAlert *alert=[NSAlert alertWithError:error]; [alert runModal]; return; } //parse the xml response [doc release]; [doc setCharacterEncoding:@iso-8859-1]; I'm guessing that doc is initially nil, so the above two lines are doing nothing (messages sent to nil). //NSString *xmlstring = [NSString stringWithContentsOfURL:url usedEncoding:@iso-8859-1 error:error]; doc=[[NSXMLDocument alloc]initWithData:urlData options:0 error:error ]; //doc=[[NSXMLDocument alloc]initWithContentsOfURL:url options:0 error:error]; //doc=[[NSXMLDocument alloc]initWithXMLString:xmlstring options:0 error:error]; I get an error telling me that the input is not in UTF-8 encoding. I know the input isn't UTF-8, but how can I get it to accept the iso-8859-1 file? You can probably simplify this a bit by using stringWithContentsOfURL:encoding:error. Note 'encoding' and not 'usedEncoding'. The former allows you to specify the encoding. In this case, use the constant NSISOLatin1StringEncoding (which is ISO_8859-1). Side note. Some parsers are especially picky about encoding names, so best to always use the constants. The official string for this particular encoding is ISO_8859-1. Some parsers allow aliases or modifications as well (hyphens, lowercase, etc.) Then, feed the string (which is now properly decoded) into a new XML doc for parsing: NSXMLDocument* theXMLDoc = [[NSXMLDocument alloc] initWithXMLString:theString options:myOptions error:myError]; //do work [theXMLDoc release]; ___ Ricky A. Sharp mailto:[EMAIL PROTECTED] Instant Interactive(tm) http://www.instantinteractive.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Reading in XML with iso-8859-1 encoding?
Is this 10.5 only? It doesn't seem to be recognised by xcode 2.5, and it doesn't run on my machine at all. I should have mentioned I'm targeting 10.4 with this. Sorry, On 6 Dec 2008, at 12:58, Ricky Sharp wrote: You can probably simplify this a bit by using stringWithContentsOfURL:encoding:error. Note 'encoding' and not 'usedEncoding'. The former allows you to specify the encoding. In this case, use the constant NSISOLatin1StringEncoding (which is ISO_8859-1). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Reading in XML with iso-8859-1 encoding?
On Dec 6, 2008, at 7:17 AM, Amy Gibbs wrote: Is this 10.5 only? It doesn't seem to be recognised by xcode 2.5, and it doesn't run on my machine at all. I should have mentioned I'm targeting 10.4 with this. stringWithContentsOfURL:encoding:error is in 10.4 and later. Do you have the proper SDK specified (e.g. 10.4 universal?) On 6 Dec 2008, at 12:58, Ricky Sharp wrote: You can probably simplify this a bit by using stringWithContentsOfURL:encoding:error. Note 'encoding' and not 'usedEncoding'. The former allows you to specify the encoding. In this case, use the constant NSISOLatin1StringEncoding (which is ISO_8859-1). ___ Ricky A. Sharp mailto:[EMAIL PROTECTED] Instant Interactive(tm) http://www.instantinteractive.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Reading in XML with iso-8859-1 encoding?
In my project details I've got 10.4 (Universal) selected, I've got xcode set up to do that autocomplete type thing, and it doesn't come up with encoding for NSString initWithContentsoOfURL, it does have encodingOnlyStreamAction? On 6 Dec 2008, at 13:24, Ricky Sharp wrote: On Dec 6, 2008, at 7:17 AM, Amy Gibbs wrote: Is this 10.5 only? It doesn't seem to be recognised by xcode 2.5, and it doesn't run on my machine at all. I should have mentioned I'm targeting 10.4 with this. stringWithContentsOfURL:encoding:error is in 10.4 and later. Do you have the proper SDK specified (e.g. 10.4 universal?) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Reading in XML with iso-8859-1 encoding?
On Sat, Dec 6, 2008 at 8:49 AM, Amy Gibbs [EMAIL PROTECTED] wrote: In my project details I've got 10.4 (Universal) selected, I've got xcode set up to do that autocomplete type thing, and it doesn't come up with encoding for NSString initWithContentsoOfURL, it does have encodingOnlyStreamAction? Xcode's code completion is, to put it mildly, poor. If it doesn't find a particular method that should be there, just type it out longhand. If the compiler then complains about not finding it, then you might have an actual problem. Mike ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]