XML Parser parse into string

Discussion in 'iOS Programming' started by roeik, Oct 15, 2009.

  1. macrumors member

    Joined:
    Dec 25, 2008
    #1
    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

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #2
    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. thread starter macrumors member

    Joined:
    Dec 25, 2008
    #3
    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?

    Thanks.
     
  4. macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #4
    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

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    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