属性の値を取得します。
オーバーロードの一覧
指定したインデックスの属性の値を取得します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Overrides Public Function GetAttribute(Integer) As String
[JScript] public override function GetAttribute(int) : String;
指定した名前の属性の値を取得します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Overrides Public Function GetAttribute(String) As String
[JScript] public override function GetAttribute(String) : String;
指定したローカル名および名前空間 URI に関連付けられた属性の値を取得します。
.NET Compact Framework でもサポート。
[Visual Basic] Overloads Overrides Public Function GetAttribute(String, String) As String
[JScript] public override function GetAttribute(String, String) : String;
使用例
[Visual Basic, C#, C++] ISBN 属性の値を取得する例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、GetAttribute のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Imports System
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlTextReader = Nothing
Try
'Load the reader with the XML file.
reader = New XmlTextReader("attrs.xml")
'Read the ISBN attribute.
reader.MoveToContent()
Dim isbn As String = reader.GetAttribute("ISBN")
Console.WriteLine("The ISBN value: " & isbn)
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub 'Main
End Class 'Sample
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextReader reader = null;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader("attrs.xml");
//Read the ISBN attribute.
reader.MoveToContent();
string isbn = reader.GetAttribute("ISBN");
Console.WriteLine("The ISBN value: " + isbn);
}
finally
{
if (reader != null)
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()
{
XmlTextReader* reader = 0;
try
{
//Load the reader with the XML file.
reader = new XmlTextReader(S"attrs.xml");
//Read the ISBN attribute.
reader->MoveToContent();
String* isbn = reader->GetAttribute(S"ISBN");
Console::WriteLine(S"The ISBN value: {0}", isbn);
}
__finally
{
if (reader != 0)
reader->Close();
}
}
この例では、入力として、 attrs.xml というファイルを使用しています。
<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。