XmlTextReader.MoveToFirstAttribute Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Passa al primo attributo.
public:
override bool MoveToFirstAttribute();
public override bool MoveToFirstAttribute();
override this.MoveToFirstAttribute : unit -> bool
Public Overrides Function MoveToFirstAttribute () As Boolean
Valori restituiti
true se esiste un attributo (il lettore passa al primo attributo); in caso contrario, false (la posizione del lettore non cambia).
Esempio
Nell'esempio seguente viene restituito il valore del primo attributo del nodo radice.
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 genre attribute.
reader.MoveToContent();
reader.MoveToFirstAttribute();
string genre=reader.Value;
Console.WriteLine("The genre value: " + genre);
}
finally
{
if (reader != null)
reader.Close();
}
}
} // End class
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 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
End Class
Nell'esempio viene usato il file , attrs.xml, come input.
<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>
Commenti
Note
È consigliabile creare XmlReader istanze usando il XmlReader.Create metodo per sfruttare le nuove funzionalità.