• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Decoding HTML Entities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 &amp; 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 "&amp;auml;" into an "d", instead of being "&auml;".

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.


References: 
 >Decoding HTML Entities (From: Michael Becker <email@hidden>)

  • Prev by Date: Getting glyphs and their outlines
  • Next by Date: Re: Clever way to replace in a NSString
  • Previous by thread: Decoding HTML Entities
  • Next by thread: Re: Decoding HTML Entities
  • Index(es):
    • Date
    • Thread