Go Back   Velocity Reviews > Newsgroups > Microsoft Certification
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Microsoft Certification - Question regarding 70-528 --> XmlReader methods

 
Thread Tools Search this Thread
Old 03-18-2007, 07:32 PM   #1
Default Question regarding 70-528 --> XmlReader methods


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-file:
<?xml version="1.0"?>
<bookstore specialty="novel">
<book style="autobiography">
<author>
<first-name>Joe</first-name>
<last-name>Bob</last-name>
<award>Trenton Literary</award>
</author>
<price>12</price>
</book>
<book style="textbook">
<author>
<first-name>Mary</first-name>
<last-name>Bob</last-name>
</author>
<price>55</price>
</book>
<book style="novel" id="myfave">
<author>
<first-name>Toni</first-name>
<last-name>Bob</last-name>
</author>
</book>
</bookstore>

Code Behind file:

using (XmlReader reader = XmlReader.Create("book.xml"))
{
reader.MoveToContent();
reader.Read();
reader.Skip();
reader.Skip();
reader.ReadStartElement("book");
reader.ReadStartElement("author");
reader.ReadStartElement("first-name");
xmlLabel.Text = reader.ReadString();
reader.ReadEndElement();
reader.ReadStartElement("last-name");
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




Martin Eckart
  Reply With Quote
Old 03-19-2007, 07:45 AM   #2
Nail
 
Posts: n/a
Default Re: Question regarding 70-528 --> XmlReader methods
You should use settings of XmlReader, like this:

XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create("book.xml", settings))
{
....
}

--
Nail
[MCPD: WEB]




Nail
  Reply With Quote
Reply

« cutouts | New MCP »

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
DVD Making Methods, Data Quality Question Cori DVD Video 13 03-23-2007 03:25 PM
"Installing two drives" question - what next? Jim A+ Certification 12 08-07-2005 01:19 PM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good God DVD Video 3 04-25-2005 04:19 PM
Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good Filthy Mcnasty DVD Video 0 04-25-2005 04:29 AM
Re: Safe Mode Question (A+ question) Gordon Findlay A+ Certification 0 06-16-2004 10:48 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46