次の方法で共有


XmlValidatingReader.Item プロパティ

指定した属性の値を取得します。

[C#] C# では、このプロパティは XmlValidatingReader クラスのインデクサになります。

オーバーロードの一覧

指定したインデックスの属性の値を取得します。

[Visual Basic] Overloads Overrides Public Default ReadOnly Property Item(Integer) As String

[C#] public override string this[int] {get;}

[C++] public: __property String* get_Item(int);

[JScript] XmlValidatingReader.Item (int)

指定した名前の属性の値を取得します。

[Visual Basic] Overloads Overrides Public Default ReadOnly Property Item(String) As String

[C#] public override string this[string] {get;}

[C++] public: __property String* get_Item(String*);

[JScript] XmlValidatingReader.Item (String)

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

[Visual Basic] Overloads Overrides Public Default ReadOnly Property Item(String, String) As String

[C#] public override string this[string, string] {get;}

[C++] public: __property String* get_Item(String*, String*);

[JScript] XmlValidatingReader.Item (String, String)

使用例

[Visual Basic, C#, C++] ISBN 属性の値を読み取る例を次に示します。

[Visual Basic, C#, C++] メモ   ここでは、Item プロパティ (XmlValidatingReader インデクサ) のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
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.Item("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["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 -> Item[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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

XmlValidatingReader クラス | XmlValidatingReader メンバ | System.Xml 名前空間