Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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