XmlValidatingReader.GetAttribute 메서드

정의

특성의 값을 가져옵니다.

오버로드

GetAttribute(Int32)

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

GetAttribute(String)

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

GetAttribute(String, String)

지정된 로컬 이름이나 네임스페이스 URI(Uniform Resource Identifier)가 있는 특성의 이름을 가져옵니다.

GetAttribute(Int32)

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

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입니다.

반환

String

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

예외

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

설명

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

참고

클래스는 XmlValidatingReader .NET Framework 2.0에서 사용되지 않습니다. 클래스 및 메서드를 사용하여 유효성 XmlReader 검사 인스턴스를 XmlReaderSettings Create 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

추가 정보

적용 대상

GetAttribute(String)

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

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

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

반환

String

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

예제

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

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the validating reader.
   XmlTextReader^ txtreader = gcnew XmlTextReader( "attrs.xml" );
   XmlValidatingReader^ reader = gcnew XmlValidatingReader( txtreader );
   
   //Read the ISBN attribute.
   reader->MoveToContent();
   String^ isbn = reader->GetAttribute( "ISBN" );
   Console::WriteLine( "The ISBN value: {0}", isbn );
   
   //Close the reader.
   reader->Close();
}

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

public class Sample
{
  public static void Main()
  {

    //Create the validating reader.
    XmlTextReader txtreader = new XmlTextReader("attrs.xml");
    XmlValidatingReader reader = new XmlValidatingReader(txtreader);

    //Read the ISBN attribute.
    reader.MoveToContent();
    string isbn = reader.GetAttribute("ISBN");
    Console.WriteLine("The ISBN value: " + isbn);

    //Close the reader.
    reader.Close();
  }
} // End class
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main()

    'Create the validating reader.
    Dim txtreader as XmlTextReader = new XmlTextReader("attrs.xml")
    Dim reader as XmlValidatingReader = new XmlValidatingReader(txtreader)

    'Read the ISBN attribute.
    reader.MoveToContent()
    Dim isbn as string = reader.GetAttribute("ISBN")
    Console.WriteLine("The ISBN value: " + isbn)

    'Close the reader.
    reader.Close()

  End sub
End class 

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

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

설명

참고

클래스는 XmlValidatingReader .NET Framework 2.0에서 사용되지 않습니다. 클래스 및 메서드를 사용하여 유효성 XmlReader 검사 인스턴스를 XmlReaderSettings Create 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

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

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

추가 정보

적용 대상

GetAttribute(String, String)

지정된 로컬 이름이나 네임스페이스 URI(Uniform Resource Identifier)가 있는 특성의 이름을 가져옵니다.

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입니다.

반환

String

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

설명

참고

클래스는 XmlValidatingReader .NET Framework 2.0에서 사용되지 않습니다. 클래스 및 메서드를 사용하여 유효성 XmlReader 검사 인스턴스를 XmlReaderSettings 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 이 정보를 가져올 수도 있습니다.

추가 정보

적용 대상