title: Resolving html entities with NSXMLParser on iPhone
body: <p>I think I read every single web page relating to this problem but I still cannot find a solution to it, so here I am.</p>
  <p>I have an HTML web page which is not under my control and I need to parse it from my iPhone application. Here is a sample of the web page I'm talking about:</p>
  <pre><code>&lt;HTML&gt;
    &lt;HEAD&gt;
      &lt;META http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
    &lt;/HEAD&gt;
    &lt;BODY&gt;
      &lt;LI class=&quot;bye bye&quot; rel=&quot;hello 1&quot;&gt;
        &lt;H5 class=&quot;onlytext&quot;&gt;
          &lt;A name=&quot;morning_part&quot;&gt;morning&lt;/A&gt;
        &lt;/H5&gt;
        &lt;DIV class=&quot;mydiv&quot;&gt;
          &lt;SPAN class=&quot;myclass&quot;&gt;something about you&lt;/SPAN&gt; 
          &lt;SPAN class=&quot;anotherclass&quot;&gt;
            &lt;A href=&quot;http://www.google.it&quot;&gt;Bye Bye &amp;egrave; un saluto&lt;/A&gt;
          &lt;/SPAN&gt;
        &lt;/DIV&gt;
      &lt;/LI&gt;
    &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  <p>I'm using NSXMLParser and it is going well till it find the <strong>è</strong> html entity. It calls foundCharacters: for &quot;Bye Bye&quot; and then it calls <strong>resolveExternalEntityName:systemID::</strong> with an entityName of &quot;egrave&quot;.
  In this method i'm just returning the character &quot;è&quot; trasformed in an NSData, the foundCharacters is called again adding the string &quot;è&quot; to the previous one &quot;Bye Bye &quot; and then the parser raise the <strong>NSXMLParserUndeclaredEntityError</strong> error.</p>
  <p>I have no DTD and I cannot change the html file I'm parsing. Do you have any ideas on this problem?</p>
  <p><strong>Update (12/03/2010)</strong>. After the suggestion of Griffo I ended up with something like this:</p>
  <pre><code>data = [self replaceHtmlEntities:data];
  NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
  [parser setDelegate:self];
  [parser parse];
  </code></pre>
  <p>where replaceHtmlEntities:(NSData *) is something like this:</p>
  <pre><code>- (NSData *)replaceHtmlEntities:(NSData *)data {
      
      NSString *htmlCode = [[NSString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
      NSMutableString *temp = [NSMutableString stringWithString:htmlCode];
      
      [temp replaceOccurrencesOfString:@&quot;&amp;amp;&quot; withString:@&quot;&amp;&quot; options:NSLiteralSearch range:NSMakeRange(0, [temp length])];
      [temp replaceOccurrencesOfString:@&quot;&amp;nbsp;&quot; withString:@&quot; &quot; options:NSLiteralSearch range:NSMakeRange(0, [temp length])];
      ...
      [temp replaceOccurrencesOfString:@&quot;&amp;Agrave;&quot; withString:@&quot;À&quot; options:NSLiteralSearch range:NSMakeRange(0, [temp length])];
  
      NSData *finalData = [temp dataUsingEncoding:NSISOLatin1StringEncoding];
      return finalData;
      
  }
  </code></pre>
  <p>But I am still looking the best way to solve this problem. I will try TouchXml in the next days but I still think that there should be a way to do this using NSXMLParser API, so if you know how, feel free to write it here.</p>