XmlReader.GetAttribute メソッド

定義

派生クラスでオーバーライドされると、属性の値を取得します。

オーバーロード

GetAttribute(String, String)

派生クラスでオーバーライドされると、指定した LocalName および NamespaceURI の属性の値を取得します。

GetAttribute(Int32)

派生クラスでオーバーライドされると、指定したインデックスの属性の値を取得します。

GetAttribute(String)

派生クラスでオーバーライドされると、指定した Name の属性の値を取得します。

GetAttribute(String, String)

派生クラスでオーバーライドされると、指定した LocalName および NamespaceURI の属性の値を取得します。

public:
 abstract System::String ^ GetAttribute(System::String ^ name, System::String ^ namespaceURI);
public abstract string GetAttribute (string name, string namespaceURI);
public abstract string? GetAttribute (string name, string? namespaceURI);
abstract member GetAttribute : string * string -> string
Public MustOverride Function GetAttribute (name As String, namespaceURI As String) As String

パラメーター

name
String

属性のローカル名。

namespaceURI
String

属性の名前空間 URI。

戻り値

指定した属性の値。 属性が見つからないか、値が String.Empty の場合、null が返されます。 このメソッドは、リーダーを移動しません。

例外

namenullです。

先行の非同期操作が完了する前に、XmlReader メソッドが呼び出されました。 この場合、「非同期操作が既に実行されています」というメッセージと共に InvalidOperationException がスローされます。

注釈

次の XML には、特定の名前空間の 属性が含まれています。

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

属性は dt:type 、1 つの引数 (プレフィックスとローカル名) または 2 つの引数 (ローカル名と名前空間 URI) を使用して検索できます。

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 取得することもできます。

適用対象

GetAttribute(Int32)

派生クラスでオーバーライドされると、指定したインデックスの属性の値を取得します。

public:
 abstract System::String ^ GetAttribute(int i);
public abstract string GetAttribute (int i);
abstract member GetAttribute : int -> string
Public MustOverride Function GetAttribute (i As Integer) As String

パラメーター

i
Int32

属性のインデックス。 インデックスの値は、0 から始まります。 最初の属性のインデックスは 0 です。

戻り値

指定した属性の値。 このメソッドは、リーダーを移動しません。

例外

i が範囲外です。 負の値以外で、属性コレクションのサイズよりも小さくなければなりません。

先行の非同期操作が完了する前に、XmlReader メソッドが呼び出されました。 この場合、「非同期操作が既に実行されています」というメッセージと共に InvalidOperationException がスローされます。

次の例では、3 番目の属性の値を取得します。

reader.ReadToFollowing("book");
string isbn = reader.GetAttribute(2);
reader.ReadToFollowing("book")
Dim isbn As String = reader.GetAttribute(2)

適用対象

GetAttribute(String)

派生クラスでオーバーライドされると、指定した Name の属性の値を取得します。

public:
 abstract System::String ^ GetAttribute(System::String ^ name);
public abstract string GetAttribute (string name);
public abstract string? GetAttribute (string name);
abstract member GetAttribute : string -> string
Public MustOverride Function GetAttribute (name As String) As String

パラメーター

name
String

属性の限定名。

戻り値

指定した属性の値。 属性が見つからないか、値が String.Empty の場合、null が返されます。

例外

namenullです。

先行の非同期操作が完了する前に、XmlReader メソッドが呼び出されました。 この場合、「非同期操作が既に実行されています」というメッセージと共に InvalidOperationException がスローされます。

次の例では、ISBN 属性の値を取得します。

reader.ReadToFollowing("book");
string isbn = reader.GetAttribute("ISBN");
Console.WriteLine("The ISBN value: " + isbn);
reader.ReadToFollowing("book")
Dim isbn As String = reader.GetAttribute("ISBN")
Console.WriteLine("The ISBN value: " + isbn)

注釈

このメソッドは、リーダーを移動しません。

リーダーがノードに DocumentType 配置されている場合、このメソッドを使用して PUBLIC リテラルと SYSTEM リテラルを取得できます。たとえば、 reader.GetAttribute("PUBLIC")

適用対象