Which is the best, most tidy way to delete any attribute with name A, on an XmlElement and recursively?
Ive seen other similar questions but the answer is always the Attribute.Remove() function, which is only available on framework 4.5 or superior. Im working on the 3.5 framework, and i have not found yet a way that convinces me.
At the moment i have written something like this:
private void RemoveA(XmlElement elem)
{
if (elem!= null)
{
elem.RemoveAttribute("A", elem.NamespaceURI);
IEnumerator nodeList = elem.ChildNodes.GetEnumerator();
object next = nodeList.MoveNext();
while (next != null)
{
RemoveA(next as XmlElement);
next = nodeList.MoveNext();
}
}
}
Which really strikes me as an awful way of doing it, especially for the use of an Object variable, and the namespaceURI in the remove attribute method (why is there not an overload that searches the name within the current element!!?)