2013-06-01 11 views
9

Sto usando seguente metodo per mettere a nudo tutta l'HTML dalla stringa:HTMLagilitypack non rimuove tutti i tag html Come posso risolvere questo problema in modo efficiente?

public static string StripHtmlTags(string html) 
     { 
      if (String.IsNullOrEmpty(html)) return ""; 
      HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); 
      doc.LoadHtml(html); 
      return doc.DocumentNode.InnerText; 
     } 

ma sembra ignorare questo tag seguente: […]

Così la stringa restituisce decidessino:

> A hungry thief who stole a rack of pork ribs from a grocery store has 
> been sentenced to spend 50 years in prison. Willie Smith Ward felt the 
> full force of the law after being convicted of the crime in Waco, 
> Texas, on Wednesday. The 43-year-old may feel slightly aggrieved over 
> the severity of the […] 

Come può Mi assicuro che questo tipo di tag venga rimosso?

Qualsiasi tipo di aiuto è apprezzato, grazie.

+0

'' … non è un tag HTML. Un tag ha parentesi angolari. Questa è un'entità codificata. – jessehouwing

risposta

31

Prova HttpUtility.HtmlDecode

public static string StripHtmlTags(string html) 
{ 
    if (String.IsNullOrEmpty(html)) return ""; 
    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); 
    doc.LoadHtml(html); 
    return HttpUtility.HtmlDecode(doc.DocumentNode.InnerText); 
} 

HtmlDecode convertirà […] a […]

+0

Fantastico, ci proverò grazie. – Obsivus

+0

Ha funzionato perfettamente grazie. – Obsivus

+0

Se ti ha aiutato, per favore considera "accettare" la sua risposta. :) –

Problemi correlati