I’m looking a way to decode XML entities of some special characters like ( µ, Λ, μ, ν, π) for my iPad app. I went though the blogs and questions for hours to find a solution.
So I found this and I modified it by adding following code lines,
else if ([scanner scanString:@"µ" intoString:NULL])
[result appendString:@"µ"];
else if ([scanner scanString:@"&Lambda" intoString:NULL])
[result appendString:@"Λ"];
else if ([scanner scanString:@"Π" intoString:NULL])
[result appendString:@"Π"];
But I’m not feeling this as a good solution.
So, I’m looking someone’s kind help for this.
XCode4 and iOS 4.3 are my development environment.
Assuming that you’ve already decided that you’re going to do this parsing by hand, as opposed to using NSXMLParser and the appropriate entity calls in the delegate, then you probably want to use a table-driven parser for this.
Since & in XML is always the introduction to an entity, it is safe to do something like this (assuming you’re parsing XML and not HTML, which can have a significantly relaxed definition of what’s allowed):
entityDictionary would be a dictionary of key value pairs representing each entity and the string that it represents:
Or you could load from a plist using: