Assembly: System.Xml (in system.xml.dll)
Public Overrides Function MoveToFirstAttribute As Boolean
Dim instance As XmlTextReader Dim returnValue As Boolean returnValue = instance.MoveToFirstAttribute
public override bool MoveToFirstAttribute ()
public: virtual bool MoveToFirstAttribute () override
public boolean MoveToFirstAttribute ()
public override function MoveToFirstAttribute () : boolean
Valore restituito
true se esiste un attributo, ovvero il visualizzatore si sposta in corrispondenza del primo attributo; in caso contrario, false, ovvero la posizione del visualizzatore non subisce alcuna modifica. Nota |
|---|
| Nella versione Microsoft .NET Framework versione 2.0 è consigliabile creare istanze di XmlReader utilizzando il metodo System.Xml.XmlReader.Create. In questo modo è possibile sfruttare completamente le nuove funzionalità introdotte in questa versione. Per ulteriori informazioni, vedere Creazione di lettori XML. |
Nell'esempio che segue viene ottenuto il valore del primo attributo del nodo radice.
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 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
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
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { XmlTextReader^ reader = nullptr; try { //Load the reader with the XML file. reader = gcnew XmlTextReader( "attrs.xml" ); //Read the genre attribute. reader->MoveToContent(); reader->MoveToFirstAttribute(); String^ genre = reader->Value; Console::WriteLine( "The genre value: {0}", genre ); } finally { if ( reader != nullptr ) reader->Close(); } }
import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
public static void main(String[] args)
{
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.get_Value();
Console.WriteLine("The genre value: " + genre);
}
finally {
if ( reader != null ) {
reader.Close();
}
}
} //main
} // End class Sample
Nell'esempio viene utilizzato il file attrs.xml come input.
<book genre='novel' ISBN='1-861003-78' pubdate='1987'> </book>
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.
.NET Framework
Supportato in: 2.0 1.1 1.0.NET Compact Framework
Supportato in: 2.0 1.0Riferimenti
Classe XmlTextReaderMembri XmlTextReader
Spazio dei nomi System.Xml
Nota