I am using the piece of code to decode few html special characters in a XML data
+(NSString *)getNSStringFormHTMLString:(NSString *)html {
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
NSMutableAttributedString* attrDisplayString = [[NSMutableAttributedString alloc] initWithData:[html dataUsingEncoding:NSUnicodeStringEncoding]options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
return [attrDisplayString string];
}
return html;
}
This code works in handy if I am using it few number of times.
But,
My use case is, I need to parse a junk XML which has lot of encoded characters.
like this
<filter name="Added_Time">
<displayname><![CDATA[Added Time]]></displayname>
<value display="Dec - 2013"><![CDATA[Added_Time:Dec - 2013]]></value>
<value display="Feb - 2014"><![CDATA[Added_Time:Feb - 2014]]></value>
<value display="Mar - 2014"><![CDATA[Added_Time:Mar - 2014]]></value>
<value display="Apr - 2014"><![CDATA[Added_Time:Apr - 2014]]></value>
<value display="Sep - 2014"><![CDATA[Added_Time:Sep - 2014]]></value>
<value display="Nov - 2014"><![CDATA[Added_Time:Nov - 2014]]></value>
</filter>
Since the above piece of code is called repeatedly to decode every key and values, I get 100% cpu usage and parsing is going on forever. (anyhow it gets completed in 2 or 3 minutes of time)
see this
apparently,
getNSStringFormHTMLString:
is proving to be a costly operation.
Help me out!!
I need a solution to do similar task which doest consume too much of time.