XAttribute.Name 屬性

定義

取得這個屬性的擴展名稱 (Expanded 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,包含這個屬性的名稱。

範例

下列範例會建立具有三個屬性的專案。 然後,它會使用這個屬性列印出每個屬性的名稱。 此範例也會示範如何使用現有屬性的名稱來建立新的屬性。

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

適用於

另請參閱