XmlTextReader.MoveToFirstAttribute Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Passa para o primeiro atributo.
public:
override bool MoveToFirstAttribute();
public override bool MoveToFirstAttribute();
override this.MoveToFirstAttribute : unit -> bool
Public Overrides Function MoveToFirstAttribute () As Boolean
Devoluções
true se existir um atributo (o leitor passa para o primeiro atributo); caso contrário, false (a posição do leitor não muda).
Exemplos
O exemplo seguinte obtém o valor do primeiro atributo do nó raiz.
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
O exemplo usa o ficheiro , attrs.xmlcomo entrada.
<book genre='novel' ISBN='1-861003-78' pubdate='1987'>
</book>
Observações
Note
Recomendamos que crie instâncias XmlReader usando o método XmlReader.Create para aproveitar a nova funcionalidade.