XAttribute.Name Property returns the expanded name of this attribute.
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass{
public static void Main(){
XNamespace aw = "http://www.domain.com";
XElement root = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.domain.com"),
new XAttribute(aw + "Att", "content"),
new XAttribute("Att2", "different content")
);
foreach (XAttribute att in root.Attributes())
Console.WriteLine("{0}={1}", att.Name, att.Value);
XElement newRoot = new XElement(aw + "Root",
from att in root.Attributes("Att2")
select new XAttribute(att.Name, "new content"));
foreach (XAttribute att in newRoot.Attributes())
Console.WriteLine("{0}={1}", att.Name, att.Value);
}}
Related examples in the same category