views:

80

answers:

3

Hi, I am reading a xml and finaly just need to remove the CDATA Infos in my results

For example: I get:

 "<![CDATA[iPhone 4-Rückgaberecht: Deutsche Telekom kulant]]>"

just need "iPhone 4-Rückgaberecht: Deutsche Telekom kulant"

thx chris

Edit to your answers: I am not using NSXMLParser (thats the reason I make my own parser)

Found some suggestions with:

- (NSString *)stringByDecodingXMLEntities;
but dont know how to implement. I always get
> YourController may not respond to '-stringByDecodingXMLEntities" <
+1  A: 

use

  • (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock

method instead of

  • (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

thats it

Ganesh
please see my edit above
christian Muller
+1  A: 

you could try a regex

replace <!\[CDATA\[(.*)\]\]> with $1

opatut
let me know how to to in objc-C :)
christian Muller
sry, don't know anything about obj-c. Seems like google doesnt find anything either. http://stackoverflow.com/questions/422138/regular-expressions-in-an-objective-c-cocoa-application look at the accepted answer...
opatut
A: 

Ok, i solved it with that:

 NSMutableString* resultString;


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)s {
   resultString = [[NSMutableString alloc] init];
    [resultString appendString:s];
}

- (NSString*)convertEntiesInString:(NSString*)s {
    if(s == nil) {
    NSLog(@"ERROR : Parameter string is nil");
    }
    NSString* xmlStr = [NSString stringWithFormat:@"<d>%@</d>", s];
    NSData *data = [xmlStr dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
    NSXMLParser* xmlParse = [[NSXMLParser alloc] initWithData:data];
    [xmlParse setDelegate:self];
    [xmlParse parse];
    NSString* returnStr = [[NSString alloc] initWithFormat:@"%@",resultString];
  return returnStr;
}

call: myConvertedString = [self convertEntiesInString:myOriginalString];

christian Muller