I have an XDocument that looks similar to
<root>
<a>
<b foo="1" bar="2" />
<b foo="3" bar="4" />
<b foo="5" bar="6" />
<b foo="7" bar="8" />
<b foo="9" bar="10" />
</a>
</root>
我希望将属性foo更改为其他内容,将属性bar更改为其他内容。我该如何轻松实现这一点?我的当前版本(如下所示)在处理大型文档时会导致堆栈溢出,并且有一种难闻的味道。
string dd=LoadedXDocument.ToString();
foreach (var s in AttributeReplacements)
dd = dd.Replace(s.Old+"=", s.New+"=");