I'm writing one of my first C# programs. Here's what I'm trying to do:
- Open an XML document
- Navigate to a part of the XML tree and select all child elements of type
<myType> - For each
<myType>element, change an attribute (so<myType id="oldValue">would become<myType id="newValue"> - Write this modified XML document to a file.
I found the XmlDocument.SelectNodes method, which takes an XPath expression as its argument. However, it returns an XmlNodeList. I read a little bit about the difference between an XML node and an XML element, and this seems to explain why there is no XmlNode.SetAttribute method. But is there a way I can use my XPath expression to retrieve a list of XmlElement objects, so that I can loop through this list and set the id attributes for each?
(If there's some other easier way, please do let me know.)