Skips the children of the current node.
[Visual Basic]
Public Overridable Sub Skip()
[C#]
public virtual void Skip();
[C++]
public: virtual void Skip();
[JScript]
public function Skip();
Remarks
In the following XML input if the reader is positioned on the <a> node or any of its attributes, calling Skip positions the reader to the <b> node.
If the reader is positioned on a leaf node already (such as the <x> node or the text node abc), calling Skip is the same as calling Read.
<a name="bob" age="123">
<x/>abc<y/>
</a>
<b>
...
</b>
This method checks for well-formed XML.
If the reader is an XmlValidatingReader, this method also validates the skipped content.
Example
[Visual Basic, C#, C++] The following example parses an XML file starting on the second book node.
[Visual Basic]
Imports System
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim reader As XmlTextReader = Nothing
Try
' Load the XmlTextReader.
reader = New XmlTextReader("2books.xml")
reader.WhitespaceHandling = WhitespaceHandling.None
' Move the reader to the second book node.
reader.MoveToContent()
reader.Read()
reader.Skip() 'Skip the first book.
' Parse the file starting with the second book node.
Do
Select Case reader.NodeType
Case XmlNodeType.Element
Console.Write("<{0}", reader.Name)
While reader.MoveToNextAttribute()
Console.Write(" {0}='{1}'", reader.Name, reader.Value)
End While
Console.Write(">")
Case XmlNodeType.Text
Console.Write(reader.Value)
Case XmlNodeType.EndElement
Console.Write("</{0}>", reader.Name)
End Select
Loop While reader.Read()
Finally
If Not (reader Is Nothing) Then
reader.Close()
End If
End Try
End Sub
End Class
[C#]
using System;
using System.IO;
using System.Xml;
public class Sample {
public static void Main() {
XmlTextReader reader = null;
try {
// Load the XmlTextReader.
reader = new XmlTextReader("2books.xml");
reader.WhitespaceHandling = WhitespaceHandling.None;
// Move the reader to the second book node.
reader.MoveToContent();
reader.Read();
reader.Skip(); //Skip the first book.
// Parse the file starting with the second book node.
do {
switch (reader.NodeType)
{
case XmlNodeType.Element:
Console.Write("<{0}", reader.Name);
while (reader.MoveToNextAttribute()) {
Console.Write(" {0}='{1}'", reader.Name, reader.Value);
}
Console.Write(">");
break;
case XmlNodeType.Text:
Console.Write(reader.Value);
break;
case XmlNodeType.EndElement:
Console.Write("</{0}>", reader.Name);
break;
}
} while (reader.Read());
}
finally {
if (reader != null)
reader.Close();
}
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main() {
XmlTextReader* reader = 0;
try {
// Load the XmlTextReader.
reader = new XmlTextReader(S"2books.xml");
reader->WhitespaceHandling = WhitespaceHandling::None;
// Move the reader to the second book node.
reader->MoveToContent();
reader->Read();
reader->Skip(); //Skip the first book.
// Parse the file starting with the second book node.
do {
switch (reader->NodeType)
{
case XmlNodeType::Element:
Console::Write(S"<{0}",reader->Name);
while (reader->MoveToNextAttribute()) {
Console::Write(S" {0}='{1}'", reader->Name, reader->Value);
}
Console::Write(S">");
break;
case XmlNodeType::Text:
Console::Write(reader->Value);
break;
case XmlNodeType::EndElement:
Console::Write(S"</{0}>", reader->Name);
break;
}
} while (reader->Read());
}
__finally {
if (reader != 0)
reader->Close();
}
}
The example uses the file, 2books.xml, as input.
<!--sample XML fragment-->
<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
XmlReader Class | XmlReader Members | System.Xml Namespace