次の方法で共有


XmlTextReader.GetAttribute メソッド (String, String)

指定したローカル名および名前空間 URI に関連付けられた属性の値を取得します。

Overrides Overloads Public Function GetAttribute( _
   ByVal localName As String, _   ByVal namespaceURI As String _) As String
[C#]
public override string GetAttribute(stringlocalName,stringnamespaceURI);
[C++]
public: String* GetAttribute(String* localName,String* namespaceURI);
[JScript]
public override function GetAttribute(
   localName : String,namespaceURI : String) : String;

パラメータ

  • localName
    属性のローカル名。
  • namespaceURI
    属性の名前空間 URI。

戻り値

指定した属性の値。指定した属性が見つからない場合は null 参照 (Visual Basic では Nothing) が返されます。このメソッドは、リーダーを移動しません。

解説

特定の名前空間内の属性を含んでいる XML を次に示します。

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

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

String dt = reader.GetAttribute("dt:type");

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

xmlns:dt 属性を検索するには、次の引数のいずれか 1 つを使用します。

String dt3 = reader.GetAttribute("xmlns:dt");

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

Prefix プロパティを使用してこの情報を取得することもできます。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

XmlTextReader クラス | XmlTextReader メンバ | System.Xml 名前空間 | XmlTextReader.GetAttribute オーバーロードの一覧