That's right, I did not use the same objects as you. with LINQ namesapce you solve the following:
using System.Xml.XPath; // <-- Add this namespace. XNamespace ci = "http://foo.com"; XElement root = new XElement(ci + "Root", new XAttribute(XNamespace.Xmlns + "abc", "http://foo.com")); XElement childElement = new XElement(ci + "MyElement", "content"); root.Add(childElement); var str = childElement.XPathEvaluate("name()"); // <-- Tell Xpath to do the work for you :). Console.WriteLine(str);
prints
abc:MyElement
source share