0
我有一個xelement這是基本的HTML,我想快速循環所有元素是段落標記,並設置樣式屬性或追加到它。我正在做下面的事情,但它並沒有改變主元素。我怎樣才能做這項工作?XElement修改,如何編輯屬性?
XElement ele = XElement.Parse(body);
foreach (XElement pot in ele.DescendantsAndSelf("p"))
{
if (pot.Attribute("style") != null)
{
pot.SetAttributeValue("style", pot.Attribute("style").Value + " margin: 0px;");
}
else
{
pot.SetAttributeValue("style", "margin: 0px;");
}
}