If I have the following XML, how would I use LINQ to XML blank out the date fields in each video node? I wanted to do it for the purpose of a comparison in a unit test.
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<main>
<videos>
<video>
<id>00000000-0000-0000-0000-000000000000</id>
<title>Video Title</title>
<videourl>http://sample.com</videourl>
<thumbnail>http://sample.com</thumbnail>
<dateCreated>2011-01-12T18:54:56.7318386-05:00</dateCreated>
<dateModified>2011-02-12T18:54:56.7318386-05:00</dateModified>
<Numbers>
<Number>28</Number>
<Number>78</Number>
</Numbers>
</video>
<video>
<id>00000000-0000-0000-0000-000000000000</id>
<title>Video Title</title>
<videourl>http://sample.com</videourl>
<thumbnail>http://sample.com</thumbnail>
<dateCreated>2011-01-12T18:54:56.7318386-05:00</dateCreated>
<dateModified>2011-02-12T18:54:56.7318386-05:00</dateModified>
<Numbers>
<Number>28</Number>
<Number>78</Number>
</Numbers>
</video>
</videos>
If you just want to clear the contents of the nodes:
Yields:
Unfortunately it will modify all date nodes no matter where they are in your XML. Personally I’d prefer to use the XPath query in the above if given the option to be very explicit which nodes should be updated. The same can be done using pure LINQ to XML, but it’s not as elegant as this.