XmlReader.Skip Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Skips the children of the current node.
public:
virtual void Skip();
public virtual void Skip ();
abstract member Skip : unit -> unit
override this.Skip : unit -> unit
Public Overridable Sub Skip ()
An XmlReader method was called before a previous asynchronous operation finished. In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."
The following example parses an XML file starting on the second book node.
using (XmlReader reader = XmlReader.Create("2books.xml")) {
// Move the reader to the second book node.
reader.MoveToContent();
reader.ReadToDescendant("book");
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());
}
Using reader As XmlReader = XmlReader.Create("2books.xml")
' Move the reader to the second book node.
reader.MoveToContent()
reader.ReadToDescendant("book")
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()
End Using
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>
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.
The XmlReader
implementation determines whether or not the Skip
method will expand external entities. The following table describes whether the external entities are expanded for the various types of XmlReader
objects.
Type of XmlReader | Expands external entities |
---|---|
XmlTextReader | No. |
XmlReader instance created by the Create method that is reading text data. | No. |
XmlReader instance created by the Create method that is reading binary data. | Not applicable. |
A schema validating XmlReader instance created by the Create method. | Yes. |
XmlValidatingReader | Yes. |
XmlReader instance returned by a XPathNavigator object. | Not applicable. |
XmlNodeReader | No. |
XmlReader instance wrapped around another XmlReader instance. | Depends on the implementation of the underlying XmlReader. (The Skip method on the underlying XmlReader is called). |
For the asynchronous version of this method, see SkipAsync.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: