指定した名前の属性の値を取得します。
[C#] C# では、このプロパティは XmlTextReader クラスのインデクサになります。
Overrides Overloads Public Default ReadOnly Property Item( _
ByVal name As String _) As String
[C#]
public override string this[stringname] {get;}
[C++]
public: __property String* get_Item(String* name);
[JScript]
returnValue = XmlTextReaderObject.Item(name);またはreturnValue = XmlTextReaderObject(name);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- name
属性の限定名。
パラメータ [Visual Basic, C#, C++]
- name
属性の限定名。
プロパティ値
指定した属性の値。指定した属性が見つからない場合は null 参照 (Visual Basic では Nothing) が返されます。
解説
このプロパティは、リーダーを移動しません。
リーダーが DocumentType ノードに配置されている場合は、このメソッドを使用して、 reader["PUBLIC"]
などの PUBLIC リテラルおよび SYSTEM リテラルを取得できます。
使用例
[Visual Basic, C#, C++] ISBN 属性の値を取得する例を次に示します。
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("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["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->Item[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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard
参照
XmlTextReader クラス | XmlTextReader メンバ | System.Xml 名前空間 | XmlTextReader.Item オーバーロードの一覧 | GetAttribute