Created
November 5, 2014 12:27
-
-
Save domenu/b932f48bac76ec5b95b3 to your computer and use it in GitHub Desktop.
Change namespace in XML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XNamespace ns = "http://mycompany/myproduct/v2"; | |
foreach (XElement el in document.Root.DescendantsAndSelf()) | |
{ | |
el.Name = ns.GetName(el.Name.LocalName); | |
List<XAttribute> atList = el.Attributes().ToList(); | |
el.Attributes().Remove(); | |
foreach (XAttribute at in atList) | |
{ | |
el.Add(new XAttribute(ns.GetName(at.Name.LocalName), at.Value)); | |
} | |
} | |
document.Root.Add(new XAttribute(XNamespace.Xmlns + "ns", ns)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment