Question regarding 70-528 --> XmlReader methods

Discussion in 'Microsoft Certification' started by Martin Eckart, Mar 18, 2007.

  1. Hi guys,

    I am about to try exam 70-528 and am stumbling about an issue with XmlReader
    methods Skip() and Read().

    Please see the following example:

    <?xml version="1.0"?>
    <bookstore specialty="novel">
    <book style="autobiography">
    <award>Trenton Literary</award>
    <book style="textbook">
    <book style="novel" id="myfave">

    Code Behind file:

    using (XmlReader reader = XmlReader.Create("book.xml"))
    xmlLabel.Text = reader.ReadString();
    xmlLabel.Text += " " + reader.ReadString();

    So, that brings "Mary Bob". I don't understand why the Skip() method, if
    called twice, does not move fwd to the last book node and displays "Toni
    Bob". I have tried to find sth in MSDN and on the web, but without success.
    Maybe it is that I misunderstand the Read() method, but am not sure.
    For my understanding, after reader.MoveToContent() the reader is placed at
    the bookstore node. Calling Read() reads the current node (bookstore) and
    advances the reader to the next node (book). Then we call the Skip() method,
    so that we are at book style="textbook". Finally the last reader.Skip()
    advances to the third and last book node. If that would be true the result
    should be "Toni Bob", so there must be an error somewhere.

    Many thanks for your help!
    Martin Eckart, Mar 18, 2007
    1. Advertisements

  2. Martin Eckart

    Nail Guest

    You should use settings of XmlReader, like this:

    XmlReaderSettings settings = new XmlReaderSettings();
    settings.IgnoreWhitespace = true;
    using (XmlReader reader = XmlReader.Create("book.xml", settings))
    Nail, Mar 19, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.