Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Computer Certification > Microsoft Certification > Question regarding 70-528 --> XmlReader methods

Reply
Thread Tools

Question regarding 70-528 --> XmlReader methods

 
 
Martin Eckart
Guest
Posts: n/a
 
      03-18-2007
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


 
Reply With Quote
 
 
 
 
Nail
Guest
Posts: n/a
 
      03-19-2007
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]


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
XmlReader question (C#) eksilva XML 0 08-20-2009 07:24 PM
SAX XMLReader, XMLFilter, ContentHandler and XMLWriter question Jeff Calico XML 2 02-22-2006 06:13 PM
XmlReader Problem =?Utf-8?B?TGFMYUJveQ==?= ASP .Net 3 05-13-2004 08:16 AM
DataSet into XmlReader George Durzi ASP .Net 5 12-31-2003 06:22 PM
XMLReader or XMLDocument ? ASP .Net 1 12-24-2003 01:21 PM



Advertisments