XmlNodeReader.MoveToNextAttribute 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 atributo seguinte.
public:
override bool MoveToNextAttribute();
public override bool MoveToNextAttribute();
override this.MoveToNextAttribute : unit -> bool
Public Overrides Function MoveToNextAttribute () As Boolean
Devoluções
true se existir um atributo seguinte; false se não houver mais atributos.
Exemplos
O exemplo seguinte lê um livro.
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'> " +
"<title>Pride And Prejudice</title>" +
"<price>19.95</price>" +
"</book>");
//Load the XmlNodeReader
reader = new XmlNodeReader(doc);
//Read the attributes on the book element.
reader.MoveToContent();
while (reader.MoveToNextAttribute())
{
Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
}
//Move the reader to the title element.
reader.Read();
//Read the title and price elements.
Console.WriteLine(reader.ReadElementString());
Console.WriteLine(reader.ReadElementString());
}
finally
{
if (reader != null)
reader.Close();
}
}
} // End class
Option Explicit
Option Strict
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'> " & _
"<title>Pride And Prejudice</title>" & _
"<price>19.95</price>" & _
"</book>")
'Load the XmlNodeReader
reader = New XmlNodeReader(doc)
'Read the attributes on the book element.
reader.MoveToContent()
While reader.MoveToNextAttribute()
Console.WriteLine("{0} = {1}", reader.Name, reader.Value)
End While
'Move the reader to the title element.
reader.Read()
'Read the title and price elements.
Console.WriteLine(reader.ReadElementString())
Console.WriteLine(reader.ReadElementString())
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
Observações
Note
Para tirar partido das funcionalidades mais recentes, a prática recomendada é criar XmlReader instâncias usando a XmlReaderSettings classe e o Create método. Para mais informações, consulte a secção de Observações na XmlReader página de referência.
Se o nó atual não for um nó de atributo, este método é equivalente a MoveToFirstAttribute. Se MoveToNextAttribute devolver true, o leitor passa para o atributo seguinte; caso contrário, a posição do leitor não muda.