XDocument change all attribute names
Posted
by Dested
on Stack Overflow
See other posts from Stack Overflow
or by Dested
Published on 2010-04-15T06:55:01Z
Indexed on
2010/04/15
13:03 UTC
Read the original article
Hit count: 270
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>
I wish to change the attribute foo to something else, and the attribute bar to something else. How can I easily do this? My current version (below) stack overflows with large documents, and has an awful smell to it.
string dd=LoadedXDocument.ToString();
foreach (var s in AttributeReplacements)
dd = dd.Replace(s.Old+"=", s.New+"=");
© Stack Overflow or respective owner