次の方法で共有


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

次の例では、3 つの属性を持つ 要素を作成します。 次に、このプロパティを使用して、各属性の名前を出力します。 この例では、既存の属性の名前を使用した新しい属性の作成も示しています。

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形式です。

適用対象

こちらもご覧ください