View Full Version : XML Parser parse into string
Oct 15, 2009, 10:14 AM
I am using an XML parser to parse an RSS feed (parsing into strings).
For some reason I am getting the string in a different format. I think it's an HTML format since but I am not sure.
For example this text: Here is a “quote”
Will be displayed: Here is a “quote”
Any ideas how to fix this?
Oct 15, 2009, 11:05 AM
It's doing exactly what it should be. The quote characters you are using are not the ASCII quote characters, they are "smart quote" HTML character entities (ldquo and rdquo). You will either need to substitute the sequence with the proper left and right Unicode entities when you encounter them if you want the proper left and right quotes or just substitute in the standard quote character (ASCII/UTF8 char 0x22)
Oct 15, 2009, 12:07 PM
How do I substitute in the e standard quote character (ASCII/UTF8 char 0x22)?
Shall I do it with the parser or with the NSString object? Is there a method that does it?
Oct 15, 2009, 12:39 PM
The easiest method would probably be to use stringByReplacingOccurrencesOfString:withString: on the NSString instance, or replaceOccurrencesOfString:withString:options:range: if it's an NSMutableString instance, after doing the parsing. Check the documentation if you need more information on the methods.
Oct 15, 2009, 02:18 PM
just a side note here: XMLParser is (usually) much slower than LibXML2. if you are parsing hundreds of elements you may want to consider LibXML. check out Apple's "XMLPerformance" sample code to see the difference between the two parsers.