Re: Decoding HTML Entities
Re: Decoding HTML Entities
- Subject: Re: Decoding HTML Entities
- From: "M. Uli Kusterer" <email@hidden>
- Date: Mon, 29 Mar 2004 19:13:07 +0100
At 17:20 Uhr +0200 29.03.2004, Michael Becker wrote:
But I cannot see a way to decode HTML entities. I receive an
XML-string from a server and want to display the data in my
application.
Since I cannot use umlauts etc. in my source code, how can I
(efficiently) DEcode HTML?
Pic one:
a) NSAttributedString lets you init it with an HTML string. From that
you could then get the NSString.
b) Use NSLocalizedString() and put the Umlauts in your
Localizable.strings file (which is UTF-8, not ASCII, and thus may
contain Umlauts). I.e.
Localizable.strings
"A-UMLAUT" = "D";
"LOWER-A-UMLAUT" = "d";
and then where you need them:
NSString* myAe = NSLocalizedString(@"A-UMLAUT",@"");
. . .
c) Create a property list (.plist file, created using Apple's
Property List Editor) containing a dictionary with the
entity-to-character mappings as Strings. Then use
initDictionaryWithContentsOfFile: to load that table, which will work
just fine with Umlauts etc. You'll have to be careful to keep &
the last entry in the dictionary, though (best hard-code it and don't
allow it in the dictionary), because otherwise you'll screw up things
like "&auml;" into an "d", instead of being "ä".
IMHO, a is the most reliable one, and the most convenient one.
Otherwise, try to do "c", and only use "b" as a last resort, or in
other cases where you only have a single character.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.