XAttribute.Name Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the expanded name of this attribute.
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
Property Value
An XName containing the name of this attribute.
Examples
The following example creates an element with three attributes. It then uses this property to print out the name of each attribute. The example also shows creation of a new attribute using the name of an existing attribute.
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
This example produces the following output:
{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
Remarks
The expanded name returned by this property is in the form of {namespace}localname
.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기