Link to home
Start Free TrialLog in
Avatar of Conrado ZAVALA
Conrado ZAVALAFlag for Honduras

asked on

How to Select Next node using linq in xml?

hi guys... I got this problem...
I've created 4 buttons that their names are first, next, previous, last.
what i want is that when the user clicks the first button the application throws a messageBox showing the values of the first book and when the user clicks next to show in another messageBox with the next book of my xml document, the same with previous and last...
i got this xml:

<?xml version="1.0" encoding="utf-8"?>
<books>
  <book>
    <title>Beginning Visual C#</title>
    <author>Karli Watson</author>
    <code>7582</code>
  </book>
  <book>
    <title>Professional C# 2nd Edition</title>
    <author>Simon Robinson</author>
    <code>7043</code>
  </book>
  <book>
    <title>Beginning XML</title>
    <author>Fawcett</author>
    <code>1500</code>
  </book>
  <book>
    <title>Silverlight 5</title>
    <author>Diaz</author>
    <code>1501</code>
  </book>
  <book>
    <title>Professional Silverlight 4 in c#</title>
    <author>MacDonald</author>
    <code>1502</code>
  </book>
</books>

Open in new window



and i got this code:

//first button
            XElement xEle = XElement.Load(@"C:\books.xml");

            var emp1 = xEle.Descendants("book").ElementAt(0);
            

            MessageBox.Show("Title: " + emp1.Element("title").Value + System.Environment.NewLine + "Author: " + emp1.Element("author").Value + System.Environment.NewLine + "Code: " + emp1.Element("code").Value);

Open in new window


what can i do for the next button?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Conrado ZAVALA

ASKER

what would be the actual type name of var?? i don't get it yet... xD
XElement