+ (NSString *)extractTextFromXML:(NSString *)xml{
//Will hold just the text
NSMutableString *text = [NSMutableString string];
NSInteger startOfSubstring = 0;
//Finds first instance of "<"
NSRange startTagRange = [xml rangeOfString:@"<"];
while(startTagRange.location != NSNotFound){
//Extracts text from last location up to "<"
NSString *substring = [xml substringWithRange:NSMakeRange(startOfSubstring, startTagRange.location-startOfSubstring)];
//Removes whitespace from substring
[text appendString:[substring stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
//Searches for ">" from "<" to end of string
NSRange startTagToEndRange = NSMakeRange(startTagRange.location, [xml length]-startTagRange.location);
NSRange endTagRange = [xml rangeOfString:@">" options:NSCaseInsensitiveSearch range:startTagToEndRange];
//If ">" found, then sets next location of substring to after that
if(endTagRange.location != NSNotFound){
startOfSubstring = endTagRange.location+1;
}
//If no ">", then appends rest of string and returns
else{
[text appendString:[xml substringFromIndex:startTagRange.location]];
return text;
}
//Finds next "<" in string
NSRange endTagToEndRange = NSMakeRange(startOfSubstring, [xml length]-startOfSubstring);
startTagRange = [xml rangeOfString:@"<" options:NSCaseInsensitiveSearch range:endTagToEndRange];
}
return text;
}