XmlTextReader.MoveToFirstAttribute Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Se mueve al primer atributo.
public:
override bool MoveToFirstAttribute();
public override bool MoveToFirstAttribute();
override this.MoveToFirstAttribute : unit -> bool
Public Overrides Function MoveToFirstAttribute () As Boolean
Devoluciones
Es true si existe un atributo (el lector se desplaza hasta el primer atributo); en caso contrario, es false (no cambia la posición del lector).
Ejemplos
En el ejemplo siguiente se obtiene el valor del primer atributo del nodo raíz.
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
En el ejemplo se usa el archivo , attrs.xmlcomo entrada.
<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>
Comentarios
Nota
A partir de .NET Framework 2.0, se recomienda crear XmlReader instancias mediante el XmlReader.Create método para aprovechar las nuevas funcionalidades.