次の方法で共有


XmlReader.GetAttribute メソッド

定義

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

オーバーロード

名前 説明
GetAttribute(String, String)

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

GetAttribute(Int32)

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

GetAttribute(String)

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

GetAttribute(String, String)

ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs

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

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)

ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs

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

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)

ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs
ソース:
XmlReader.cs

派生クラスでオーバーライドされると、指定した 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")

適用対象