I need to parse an HTML document using NSXmlParser.As you know there are three main delegate methods parser:didStartElement….,parser:DidEndElement:….. and parser:foundCharacters: methods. I really can’t understand how the last method is useful? What does it provide that parser:didStartElement:.. method does not.Let’s say I have the following piece of an HTML document:
<img src="http://eurovision.az/attachments/news/main_images/
b_a71309d9c34df72adbbb29d506bc5034.jpg" alt=""
rel="http://eurovision.az/attachments/news/main_images/
t_a71309d9c34df72adbbb29d506bc5034.jpg" title="#htmlcaption1" />
Now, to parse this part of the HTML at which point would I use which of these three methods? Thanks ahead.
In the exmaple HTML that you’ve given the
parser:foundCharactersmethod isn’t very useful. This is because it reads the characters in the value part of an XML/XHTML element.So, given the following XML:
And the following almost-code:
Then
everythingStringwould contain “bonjoydell”. parser:didStartElement would be called on finding the<person>,<firstname>and<secondname>tags. parser:didEndElement would be called on finding the</firstname>,</secondname>and</person>tags.parser:didStartElementdoesn’t give you access to the values contained in the XML elements but it does give you access to the attribute values.So, back to your example, the only delegate methods that would be usefully called are
parser:didStartElementandparser:didEndElementand being as the tag in your example is self contained and has no child elements onlyparser:didStartElementwould yield any useful data.