1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

XML Parser parse into string

Discussion in 'iPhone/iPad Programming' started by roeik, Oct 15, 2009.

  1. macrumors member

    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 &#8220quote&#8221

    Any ideas how to fix this?

    Thanks. Roei.
  2. macrumors 6502a

    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)
  3. macrumors member

    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?

  4. macrumors 6502a

    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.
  5. Guest


    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.

Share This Page