XmlTextReader.GetAttribute 메서드

정의

특성의 값을 가져옵니다.

오버로드

GetAttribute(Int32)

지정된 인덱스가 있는 특성의 값을 가져옵니다.

GetAttribute(String)

지정된 이름이 있는 특성의 값을 가져옵니다.

GetAttribute(String, String)

지정된 로컬 이름과 네임스페이스 URI가 있는 특성의 값을 가져옵니다.

설명

참고

.NET Framework 2.0부터는 메서드를 사용하여 XmlReader.Create 새 기능을 활용하여 인스턴스를 만드는 XmlReader 것이 좋습니다.

GetAttribute(Int32)

Source:
XmlTextReader.cs
Source:
XmlTextReader.cs
Source:
XmlTextReader.cs

지정된 인덱스가 있는 특성의 값을 가져옵니다.

public:
 override System::String ^ GetAttribute(int i);
public override string GetAttribute (int i);
override this.GetAttribute : int -> string
Public Overrides Function GetAttribute (i As Integer) As String

매개 변수

i
Int32

특성의 인덱스입니다. 인덱스는 0부터 시작합니다. 첫 번째 특성의 인덱스는 0입니다.

반환

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

예외

i 매개 변수가 0보다 작거나 AttributeCount보다 크거나 같은 경우

설명

참고

.NET Framework 2.0부터는 메서드를 사용하여 XmlReader.Create 새 기능을 활용하여 인스턴스를 만드는 XmlReader 것이 좋습니다.

이 메서드는 판독기를 이동하지 않습니다.

추가 정보

적용 대상

GetAttribute(String)

Source:
XmlTextReader.cs
Source:
XmlTextReader.cs
Source:
XmlTextReader.cs

지정된 이름이 있는 특성의 값을 가져옵니다.

public:
 override System::String ^ GetAttribute(System::String ^ name);
public override string? GetAttribute (string name);
public override string GetAttribute (string name);
override this.GetAttribute : string -> string
Public Overrides Function GetAttribute (name As String) As String

매개 변수

name
String

특성의 정규화된 이름입니다.

반환

지정된 특성의 값을 반환합니다. 특성이 없으면 null이 반환됩니다.

예제

다음 예제에서는 ISBN 특성의 값을 가져옵니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = nullptr;
   try
   {
      
      //Load the reader with the XML file.
      reader = gcnew XmlTextReader( "attrs.xml" );
      
      //Read the ISBN attribute.
      reader->MoveToContent();
      String^ isbn = reader->GetAttribute( "ISBN" );
      Console::WriteLine( "The ISBN value: {0}", isbn );
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}
using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    XmlTextReader reader = null;

    try
    {
       //Load the reader with the XML file.
       reader = new XmlTextReader("attrs.xml");

       //Read the ISBN attribute.
       reader.MoveToContent();
       string isbn = reader.GetAttribute("ISBN");
       Console.WriteLine("The ISBN value: " + isbn);
     }
     finally
     {
        if (reader != null)
          reader.Close();
      }
  }
} // End class
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing
        
        Try
            'Load the reader with the XML file.
            reader = New XmlTextReader("attrs.xml")
            
            'Read the ISBN attribute.
            reader.MoveToContent()
            Dim isbn As String = reader.GetAttribute("ISBN")
            Console.WriteLine("The ISBN value: " & isbn)
        
        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
    End Sub
End Class

이 예제에서는 파일 를 attrs.xml입력으로 사용합니다.


<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>

설명

참고

.NET Framework 2.0부터는 메서드를 사용하여 XmlReader.Create 새 기능을 활용하여 인스턴스를 만드는 XmlReader 것이 좋습니다.

이 메서드는 판독기를 이동하지 않습니다.

판독기가 노드에 배치된 경우 이 메서드를 DocumentType 사용하여 PUBLIC 및 SYSTEM 리터럴을 가져올 수 있습니다. 예를 들면 다음과 같습니다. reader.GetAttribute("PUBLIC")

추가 정보

적용 대상

GetAttribute(String, String)

Source:
XmlTextReader.cs
Source:
XmlTextReader.cs
Source:
XmlTextReader.cs

지정된 로컬 이름과 네임스페이스 URI가 있는 특성의 값을 가져옵니다.

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

매개 변수

localName
String

특성의 로컬 이름입니다.

namespaceURI
String

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

반환

지정된 특성의 값을 반환합니다. 특성이 없으면 null이 반환됩니다. 이 메서드는 판독기를 이동하지 않습니다.

설명

참고

.NET Framework 2.0부터는 메서드를 사용하여 XmlReader.Create 새 기능을 활용하여 인스턴스를 만드는 XmlReader 것이 좋습니다.

다음 XML에는 특정 네임스페이스의 특성이 포함되어 있습니다.

<test xmlns:dt="urn:datatypes" dt:type="int"/>

하나의 인수(접두사 및 로컬 이름) 또는 두 개의 인수(로컬 이름 및 네임스페이스 URI)를 사용하여 특성을 조회 dt:type 할 수 있습니다.

String dt = reader.GetAttribute("dt:type");
String dt2 = reader.GetAttribute("type","urn:datatypes");

특성을 조회 xmlns:dt 하려면 다음 인수 중 하나를 사용합니다.

String dt3 = reader.GetAttribute("xmlns:dt");
String dt4 = reader.GetAttribute("dt",http://www.w3.org/2000/xmlns/);

속성을 사용하여 Prefix 이 정보를 가져올 수도 있습니다.

추가 정보

적용 대상