Sdílet prostřednictvím


XmlReader.Skip Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Skips the children of the current node.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Overridable Sub Skip
public virtual void 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.

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

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.

XmlReader instance wrapped around another XmlReader instance.

Depends on the implementation of the underlying XmlReader. (The Skip method on the underlying XmlReader is called).

Examples

Dim xmlString As String = _
    "<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>"

' Load the file and ignore all white space.
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString), settings)
    ' Position the reader on the second book node
    reader.ReadToFollowing("book")
    reader.Skip()

    ' Create another reader that contains just the second book node.
    Dim inner As XmlReader = reader.ReadSubtree()
    ' Do additional processing on the inner reader. After you 
    ' are done, you can call Close on the inner reader and 
    ' continue processing using the original reader.
End Using

String xmlString =
    @"<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>";

// Load the file and ignore all white space.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString), settings))
{
    // Position the reader on the second book node
    reader.ReadToFollowing("book");
    reader.Skip();

    // Create another reader that contains just the second book node.
    XmlReader inner = reader.ReadSubtree();

    // Do additional processing on the inner reader. After you 
    // are done, you can call Close on the inner reader and 
    // continue processing using the original reader.

}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.