Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

XML + C# - Iterating through nodes


  • Please log in to reply

#1
Ryan_88

Ryan_88

    Member

  • Member
  • PipPipPip
  • 110 posts
hi guys, am writing a program to iterate through nodes stored in an XML file, however i want to be able to iterate through each one at the click of a button (not all at once). i can't seem to get this working. i have found a tutorial that iterates through 3 nodes and then displays each result, but i can't modify it to do one at a time at the click of a button. this may be how i've coded the methods and the buttons. could someone please tell me if they see a way to do what i want? i've been on it a while and i think i'm getting tunnel vision on this problem!

code:

static public void NextQuestion(string expression)
{

XPathDocument doc = new XPathDocument(xmlFilePath);
XPathNavigator nav = doc.CreateNavigator();

XPathExpression expr;
expr = nav.Compile(expression);
XPathNodeIterator iterator = nav.Select(expr);

iterator.MoveNext();
XPathNavigator nav2 = iterator.Current.Clone();
nav2.MoveToFirstChild();
question = nav2.Value;


}

code for button that calls the method:

private void button5_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
quizmaster.Program.NextQuestion("/questionBase/question/questionBody"); //what nodes to find in the xml structure
listBox1.Items.Add(quizmaster.Program.question); //add the variable question to the listBox
}

thanks
ryan
  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP