XAttribute.Name 属性

定义

获取此属性的扩展名。

public:
 property System::Xml::Linq::XName ^ Name { System::Xml::Linq::XName ^ get(); };
public System.Xml.Linq.XName Name { get; }
member this.Name : System.Xml.Linq.XName
Public ReadOnly Property Name As XName

属性值

XName

一个包含此属性 (Attribute) 名称的 XName

示例

以下示例创建一个具有三个属性的元素。 然后,它使用此属性输出每个属性的名称。 该示例还演示如何使用现有属性的名称创建新属性。

XNamespace aw = "http://www.adventure-works.com";  
XElement root = new XElement(aw + "Root",  
    new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.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);  
Console.WriteLine("");  

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);  
Dim root As XElement = _   
    <aw:Root xmlns:aw='http://www.adventure-works.com'  
        aw:Att='content'  
        Att2='different content'/>  

For Each att As XAttribute In root.Attributes()  
    Console.WriteLine("{0}={1}", att.Name, att.Value)  
Next  
Console.WriteLine("")  

Dim NewRoot As XElement = _  
<Root  
    <%= _  
        From att In root.Attributes("Att2") _  
        Select New XAttribute(att.Name, "new content") _  
    %>>_  
</Root>  

For Each att As XAttribute In NewRoot.Attributes()  
    Console.WriteLine("{0}={1}", att.Name, att.Value)  
Next  

该示例产生下面的输出:

{http://www.w3.org/2000/xmlns/}aw=http://www.adventure-works.com  
{http://www.adventure-works.com}Att=content  
Att2=different content  

Att2=new content  

注解

此属性返回的扩展名称的格式 {namespace}localname为 .

适用于

另请参阅