私はDIV要素のstyle属性からスタイル定義を削除しようとしています。 HTMLコード:
<div class="el1" style="width:800px; max-width:100%" />
...
<div class="el2" style="width:800px; max-width:100%" />
操作を適用するために必要な要素が1つ以上ある場合があります。
ここまではHtmlAgilityPackを使っています。
foreach (HtmlNode div in doc.DocumentNode.SelectNodes("//div[@style]"))
{
if (div != null)
{
div.Attributes["style"].Value["max-width"].Remove(); //Remove() does not appear to be a function
}
}
私の思考プロセスは、スタイル属性を持つものを選択することでした。最大幅の定義を探して削除します。
これがどのように達成されるかについてのガイダンスは?
Marcelが私に正しい方向を指してくれている:
私のために働く解決策はここにあります。
HtmlNodeCollection divs = doc.DocumentNode.SelectNodes("//div[@style]");
if (divs != null)
{
foreach (HtmlNode div in divs)
{
string style = div.Attributes["style"].Value;
string pattern = @"max-width(.*?)(;)";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
string newStyle = regex.Replace(style, String.Empty);
div.Attributes["style"].Value = newStyle;
}
}