次の方法で共有


XmlNodeReader.MoveToFirstAttribute メソッド

最初の属性に移動します。

Overrides Public Function MoveToFirstAttribute() As Boolean
[C#]
public override bool MoveToFirstAttribute();
[C++]
public: bool MoveToFirstAttribute();
[JScript]
public override function MoveToFirstAttribute() : Boolean;

戻り値

属性が存在する場合は true で、リーダーが最初の属性に移動します。それ以外の場合は false で、リーダーの位置が変更されません。

使用例

[Visual Basic, C#, C++] ルート ノードの最初の属性の値を取得する例を次に示します。

 
Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load the XML document.
            Dim doc As New XmlDocument()
            doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " & _
                        "</book>")
            
            'Load the XmlNodeReader 
            reader = New XmlNodeReader(doc)
            
            'Read the genre attribute.
            reader.MoveToContent()
            reader.MoveToFirstAttribute()
            Dim genre As String = reader.Value
            Console.WriteLine("The genre value: " & genre)
        
        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()
  {
    XmlNodeReader reader = null;

    try
    {
       //Create and load the XML document.
       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book genre='novel' ISBN='1-861003-78' publicationdate='1987'> " +
                   "</book>"); 

       //Load the XmlNodeReader 
       reader = new XmlNodeReader(doc);
  
       //Read the genre attribute.
       reader.MoveToContent();
       reader.MoveToFirstAttribute();
       string genre=reader.Value;
       Console.WriteLine("The genre value: " + genre);

     } 
     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()
{
   XmlNodeReader* reader = 0;

   try
   {
      //Create and load the XML document.
      XmlDocument* doc = new XmlDocument();
      doc->LoadXml(S"<book genre='novel' ISBN='1-861003-78' publicationdate='1987'></book>"); 

      //Load the XmlNodeReader 
      reader = new XmlNodeReader(doc);

      //Read the genre attribute.
      reader->MoveToContent();
      reader->MoveToFirstAttribute();
      String* genre=reader->Value;
      Console::WriteLine(S"The genre value: {0}", genre);

   } 
   __finally 
   {
      if (reader != 0)
         reader->Close();
   }
}

[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 ファミリ, .NET Compact Framework - Windows CE .NET

参照

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