Change xml attribute name in
Using LINQ-XML , you can remove the existing attribute, and then add a new one.
Xml markup:
<?xml version="1.0" encoding="utf-8"?> <root> <text align="center" other="attribute">Something</text> </root> code:
XDocument doc = XDocument.Load(file); var element = doc.Root.Element("text"); var attList = element.Attributes().ToList(); var oldAtt = attList.Where(p => p.Name == "align").SingleOrDefault(); if (oldAtt != null) { XAttribute newAtt = new XAttribute("text-align", oldAtt.Value); attList.Add(newAtt); attList.Remove(oldAtt); element.ReplaceAttributes(attList); doc.Save(file); } Using linq-to-xml , you can use the XElement.ReplaceAttributes xml attribute update method, something like this:
XElement data = XElement.Parse (@"<text align=""center""> d hhdohd </text>"); data.ReplaceAttributes( new XAttribute("text-align", "center") );