I have Xml which looks like this:
<DataMapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SqlTable />
<Level_01s>
<DataParameter>
<SqlTable>MY-Table-Name</SqlTable>
<Children>
<DataParameter>
<SqlTable>MY-Table-Name</SqlTable>
<Children>
<DataParameter>
<SqlTable>MY-Table-Name</SqlTable>
<Children>
<DataParameter>
<SqlTable>[All]</SqlTable>
<Children />
</DataParameter>
<DataParameter>
<SqlTable>MY-Table-Name</SqlTable>
<Children>
<DataParameter>
<SqlTable>[All]</SqlTable>
<Children />
</DataParameter>
</Children>
</DataParameter>
</Children>
</DataParameter>
</Children>
</DataParameter>
</Children>
</DataParameter>
</Level_01s>
</ DataMapper>
What I'd like to do is update all instances of the element. The issue that I have is that the DataParameters may go n-levels deep.
How can I recursivly ensure I update all of these?
I am using this code to update Root-level elements:
XDocument xdoc = XDocument.Parse(myxmlstring);
var element = xdoc.Elements("SqlTable").Single();
element.Value = "foo";
xdoc.Save("file.xml");
via http://stackoverflow.com/questions/544310/best-way-to-change-the-value-of-an-element-in-c