Il nome di un elemento XML non può essere cambiato direttamente. Bisogna che crei un nuovo elemento con un nuovo nome e che copi la struttura del primo nel secondo nodo.
Ti lascio un esempio:
using System.Xml;
public class Test20031016
{
public static void Main (string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"test20031011.xml");
XmlElement element = (XmlElement)
doc.GetElementsByTagName("PRIMOELEMENTO")[0];
XmlElement newElement = copyElementToName(element, "NUOVOELEMENTO");
doc.DocumentElement.AppendChild(newElement);
}
public static XmlElement copyElementToName (XmlElement element,
string tagName)
{
XmlElement newElement = element.OwnerDocument.CreateElement(tagName);
for (int i = 0; i < element.Attributes.Count; i++)
{
newElement.SetAttributeNode((XmlAttribute)
element.Attributes[i].CloneNode(true));
}
for (int i = 0; i < element.ChildNodes.Count; i++)
{
newElement.AppendChild(element.ChildNodes[i].CloneNode(true));
}
return newElement;
}