指定した名前の属性の値を取得します。
Overrides Overloads Public Function GetAttribute( _
ByVal name As String _) As String
[C#]
public override string GetAttribute(stringname);
[C++]
public: String* GetAttribute(String* name);
[JScript]
public override function GetAttribute(
name : String) : String;
パラメータ
- name
属性の限定名。
戻り値
指定した属性の値。指定した属性が見つからない場合は null 参照 (Visual Basic では Nothing) が返されます。
解説
このメソッドは、リーダーを移動しません。
リーダーが DocumentType ノードに配置されている場合は、このメソッドを使用して、 reader.GetAttribute("PUBLIC") などの PUBLIC リテラルおよび SYSTEM リテラルを取得できます。
使用例
[Visual Basic, C#, C++] ISBN 属性の値を取得する例を次に示します。
Imports System
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
[C#]
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
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
//Create the validating reader.
XmlTextReader* txtreader = new XmlTextReader(S"attrs.xml");
XmlValidatingReader* reader = new XmlValidatingReader(txtreader);
//Read the ISBN attribute.
reader->MoveToContent();
String* isbn = reader->GetAttribute(S"ISBN");
Console::WriteLine(S"The ISBN value: {0}", isbn);
//Close the reader.
reader->Close();
}
この例では、入力として、 attrs.xml というファイルを使用しています。
<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
XmlValidatingReader クラス | XmlValidatingReader メンバ | System.Xml 名前空間 | XmlValidatingReader.GetAttribute オーバーロードの一覧