XElement.Attribute(XName) 메서드

정의

지정된 XAttribute이 있는 이 XElementXName를 반환합니다.

public:
 System::Xml::Linq::XAttribute ^ Attribute(System::Xml::Linq::XName ^ name);
public System.Xml.Linq.XAttribute Attribute (System.Xml.Linq.XName name);
public System.Xml.Linq.XAttribute? Attribute (System.Xml.Linq.XName name);
member this.Attribute : System.Xml.Linq.XName -> System.Xml.Linq.XAttribute
Public Function Attribute (name As XName) As XAttribute

매개 변수

name
XName

가져올 XNameXAttribute입니다.

반환

XAttribute

지정된 XAttribute이 있는 XName이거나, 지정된 이름의 특성이 없으면 null입니다.

예제

다음 예제에서는 특성을 사용하여 요소를 만듭니다. 그런 다음 이 메서드를 사용하여 특성을 검색합니다.

XElement xmlTree = new XElement("Root",  
    new XAttribute("Att", "attribute content")  
);  
XAttribute att = xmlTree.Attribute("Att");  
Console.WriteLine(att);  
Dim xmlTree As XElement = <Root Att="attribute content"/>  

Dim att As XAttribute = xmlTree.Attribute("Att")  
Console.WriteLine(att)  

이 예제는 다음과 같은 출력을 생성합니다.

Att="attribute content"  

다음은 동일한 예제이지만 이 경우 XML은 네임스페이스에 있습니다. 자세한 내용은 XML 네임스페이스 작업을 참조하세요.

XNamespace aw = "http://www.adventure-works.com";  
XElement xmlTree = new XElement(aw + "Root",  
    new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),  
    new XAttribute(aw + "Att", "attribute content")  
);  
XAttribute att = xmlTree.Attribute(aw + "Att");  
Console.WriteLine(att);  
Imports <xmlns:aw="http://www.adventure-works.com">  

Module Module1  
    Sub Main()  
        Dim xmlTree As XElement = <aw:Root aw:Att="attribute content"/>  

        Dim att As XAttribute = xmlTree.Attribute(GetXmlNamespace(aw) + "Att")  
        Console.WriteLine(att)  
    End Sub  
End Module  

이 예제는 다음과 같은 출력을 생성합니다.

aw:Att="attribute content"  

설명

일부 축 메서드는 요소 또는 특성의 컬렉션을 반환합니다. 이 메서드는 단일 특성만 반환합니다. 컬렉션과 달리 싱글 이라고도 합니다.

Visual Basic 사용자는 통합 특성 축을 사용하여 지정된 이름의 특성 값을 검색할 수 있습니다.

적용 대상

추가 정보