Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two button - prev and next. When i run program it must show me first question with answers.Question in Qtextbox1. Answers in Atextbox1,Atextbox2,Atextbox3 ... /Key[1] show me first node. But i dont know how define count of nodes.
XML
 <Key>
  first question
  <Value>answer1</Value> 
  <Value>answer2</Value> 
  <Value>answer3</Value> 
  <Value>answer4</Value> 
  <Value>answer5</Value> 
  </Key>
- <Key>
  second question
  <Value>answer1</Value> 
  <Value>answer2</Value> 
  <Value>answer3</Value> 
  </Key>
- <Key>
  third question
  <Value>answer1</Value> 
  <Value>answer2</Value> 
  <Value>answer3</Value> 
  </Key>
Posted
Updated 17-May-13 8:04am
v3

 
Share this answer
 
Comments
[no name] 17-May-13 14:02pm    
/Key[1] show me first node. But i dont know how define count of nodes.
Sergey Alexandrovich Kryukov 17-May-13 14:04pm    
Keep reading then...
—SA
C#
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml("Your XML here");
XmlNodeList xnodes = xdoc.SelectNodes("/Key");
int count = xnodes.Count;
foreach (XmlNode xnode in xnodes)
{
     // TODO: Implement your code here
}
 
Share this answer
 
You may use following xpath to get the count of 'Value' node in the xml.

XML
count(//Key/Value)


To get the number of child elements in a node, we may use following xpath.

XML
count(//Key/*)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900