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;");
}
}