Problema: I È necessario rimuovere la proprietà di stile di tutti i tag <p>
e se contiene la proprietà font-weight:bold
, quindi aggiungere <b>
ad esso.Aggiungi un nodo al testo interno utilizzando HTMLAgilityPack
ad esempio: se l'html è <p style="margin-top:0pt; margin-bottom:0pt;font-weight:bold; font-weight:bold;font-size:10pt; font-family:ARIAL" align="center"> SOME TEXT HERE</p>
.
uscita dovrebbe essere: <p align="center"> <b>SOME TEXT HERE</b></p>
Sto utilizzando il seguente codice,
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(htmlPage);
foreach (var htmlTag in attributetags)
{
var Nodes = htmlDocument.DocumentNode.SelectNodes("//p");
if (Nodes != null)
{
bool flag = false;
foreach (var Node in Nodes)
{
if (Node.Attributes["style"] != null)
{
if (Node.Attributes["style"].Value.Contains("font-weight:bold"))
{
var bnode = HtmlNode.CreateNode("<b>");
Node.PrependChild(bnode);
}
Node.Attributes.Remove("style");
}
}
}
}
Ho provato anche con i contenuti Node.InsertAfter(bcnode, Node), Node.InsertBefor(bnode, Node)
ha funzionato bene! grazie :) – user2729272
@ user2729272 benvenuto :) Ho aggiunto una dichiarazione a una riga per avvolgere il contenuto del paragrafo nel tag b. Penso che sia meno leggibile, ma più compatto –