XmlNodeReader.Skip 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.
Ignora os filhos do nó atual.
public:
override void Skip();
public override void Skip();
override this.Skip : unit -> unit
Public Overrides Sub Skip ()
Exemplos
O exemplo seguinte lê o nó do elemento preço no documento XML.
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("<!-- sample XML -->" +
"<book>" +
"<title>Pride And Prejudice</title>" +
"<price>19.95</price>" +
"</book>");
//Load the XmlNodeReader
reader = new XmlNodeReader(doc);
reader.MoveToContent(); //Move to the book node.
reader.Read(); //Read the book start tag.
reader.Skip(); //Skip the title element.
Console.WriteLine(reader.ReadOuterXml()); //Read the price element.
}
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("<!-- sample XML -->" & _
"<book>" & _
"<title>Pride And Prejudice</title>" & _
"<price>19.95</price>" & _
"</book>")
'Load the XmlNodeReader
reader = New XmlNodeReader(doc)
reader.MoveToContent() 'Move to the book node.
reader.Read() 'Read the book start tag.
reader.Skip() 'Skip the title element.
Console.WriteLine(reader.ReadOuterXml()) 'Read the price element.
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.
Por exemplo, suponha que tem a seguinte entrada XML:
<a name="bob" age="123">
<x/>abc<y/>
</a>
<b>
...
</b>
Se o leitor estiver posicionado no nó "<a>" ou em qualquer um dos seus atributos, a chamada Skip posiciona o leitor no nó "<b>".
Se o leitor já estiver posicionado num nó folha (como o elemento "x" ou o nó de texto "abc"), chamar Skip é o mesmo que chamar Read.
Este método verifica se XML está bem formado.