I am trying to read a xml-file with internal html to show in a UIWebView.
I am using NSXMLParser to parse an incoming XML-file. Works like charm. However now I want to parse HTML that is included in the tags.
For instance this is parsed just fine:
<item>
<letter>a</letter>
<word>word 1</word>
<description>Yada yada</description>
</item>
However this is making the parser crash:
<item>
<letter>a</letter>
<word>word 1</word>
<description><p>Yada</p></description>
</item>
since the parser thinks it should translate
as xml-nodes obviously.
How could I change my parsing to handle internal html?
The code used in my class to parse the xml handles these nodes on method foundCharacters
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
// save the characters for the current item...
if ([currentElement isEqualToString:@"letter"]) {
[currentLetter appendString:string];
} else if ([currentElement isEqualToString:@"word"]) {
[currentWord appendString:string];
} else if ([currentElement isEqualToString:@"description"]) {
[currentDescription appendString:string];
}
}
And this on didEndElement
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
[item setObject:currentLetter forKey:@"letter"];
[item setObject:currentWord forKey:@"word"];
[item setObject:currentDescription forKey:@"description"];
[stories addObject:[item copy]];
}
}