I\'m working on an app which aggregates some feeds from the internet and reformats the content. So I\'m looking for a way to parse some HTML. Given XML and HTML are very sim
There's absolutely nothing special about "p" as the name of an element. While it is hard to be sure because you haven't provided an example of the HTML you are parsing, the problem is most likely caused by HTML that is not well-formed XML. In other words, using NSXMLParser would work on XHTML, but not necessarily plain-old HTML.
The "p" element is frequently found in HTML without the matching closing tag, which is not valid XML. My guess is that you would have to convert the HTML to XHTML before trying to parse it with an NSXMLParser
I recommend you use my DTHTMLParser which is modeled after NSXMLParser and uses libxml2 to parse HTML perfectly. You generally cannot rely on the HTML to be well-formed and be parseable as xml.
libxml2 has a HTML mode where it is able to ignore things like un-closed tags and whatever HTML might have in ideosyncrasies.
HTML parsing explained:
DTHTMLParser documentation:
Source, part of DTFoundation:
HTML is not necessarily well-formed XML, and that's the trouble when you parse it as XML.
Take the following example:
<body>
<p>123
<p>abc
<p>789
</body>
If you view this chunk of html in a browser, it would show just as what you expected. But if you parse this as xml, there would be trouble, as those p tags are not closed.