XmlElement.GetAttribute 메서드

정의

지정된 특성의 특성 값을 반환합니다.

오버로드

GetAttribute(String)

지정된 이름을 가진 특성의 값을 반환합니다.

GetAttribute(String, String)

지정된 로컬 이름과 네임스페이스 URI를 갖고 있는 특성의 값을 반환합니다.

GetAttribute(String)

지정된 이름을 가진 특성의 값을 반환합니다.

public:
 virtual System::String ^ GetAttribute(System::String ^ name);
public virtual string GetAttribute (string name);
abstract member GetAttribute : string -> string
override this.GetAttribute : string -> string
Public Overridable Function GetAttribute (name As String) As String

매개 변수

name
String

검색할 특성의 이름입니다. 정규화된 이름입니다. 일치하는 노드의 Name 속성과 일치합니다.

반환

String

지정된 특성의 값을 반환합니다. 일치 하는 특성이 없거나 특성에 지정된 값 또는 기본값이 없으면 빈 문자열이 반환됩니다.

예제

다음 예제에서는 요소에 지정된 특성이 있는지 확인합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   XmlElement^ root = doc->DocumentElement;
   
   // Check to see if the element has a genre attribute.
   if ( root->HasAttribute( "genre" ) )
   {
      String^ genre = root->GetAttribute( "genre" );
      Console::WriteLine( genre );
   }
}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    XmlElement root = doc.DocumentElement;

    // Check to see if the element has a genre attribute.
    if (root.HasAttribute("genre")){
      String genre = root.GetAttribute("genre");
      Console.WriteLine(genre);
   }
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                "<title>Pride And Prejudice</title>" & _
                "</book>")      

    Dim root as XmlElement = doc.DocumentElement

    ' Check to see if the element has a genre attribute.
    if (root.HasAttribute("genre"))
     Dim genre as String = root.GetAttribute("genre")
     Console.WriteLine(genre)
    end if
       
    Console.WriteLine("Display the modified XML...")
    Console.WriteLine(doc.InnerXml)

  end sub
end class

적용 대상

GetAttribute(String, String)

지정된 로컬 이름과 네임스페이스 URI를 갖고 있는 특성의 값을 반환합니다.

public:
 virtual System::String ^ GetAttribute(System::String ^ localName, System::String ^ namespaceURI);
public virtual string GetAttribute (string localName, string namespaceURI);
public virtual string GetAttribute (string localName, string? namespaceURI);
abstract member GetAttribute : string * string -> string
override this.GetAttribute : string * string -> string
Public Overridable Function GetAttribute (localName As String, namespaceURI As String) As String

매개 변수

localName
String

검색할 특성의 로컬 이름입니다.

namespaceURI
String

검색할 특성의 네임스페이스 URI입니다.

반환

String

지정된 특성의 값을 반환합니다. 일치 하는 특성이 없거나 특성에 지정된 값 또는 기본값이 없으면 빈 문자열이 반환됩니다.

적용 대상