![]() |
|
|
|||||||
![]() |
Microsoft Certification - Question regarding 70-528 --> XmlReader methods |
|
|
Thread Tools | Search this Thread |
|
|
#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-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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |