I’m making a small program that supposedly get all XML elements that can only contain a value. For example (please refer to the image below), <Products> though it is an element, but it should not be displayed because it just encloses all other elements that can contain value, same for <Description> (the highlighted one, sorry for my english, but hope you get me guys..)
From the image below, my program should only pick the following elements:
<Material_Number>
<Description> (the 2 elements but not including the highlighted one)
<Language>
<Material_Type>
<Base_Unit>
What I actually get is nothing…

Kindly review my code and advise:
public MainForm()
{
InitializeComponent();
XmlDataDocument xmldoc = new XmlDataDocument();
XmlNode xmlnode;
FileStream fs = new FileStream(@"C:\text.xml", FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
xmlnode = xmldoc.ChildNodes[1];
GetElements(xmlnode);
}
void GetElements(XmlNode inXmlNode)
{
XmlNode xNode;
XmlNodeList nodeList;
int i = 0;
if (inXmlNode.HasChildNodes)
{
nodeList = inXmlNode.ChildNodes;
for (i = 0; i <= nodeList.Count - 1; i++)
{
xNode = inXmlNode.ChildNodes[i];
string ss = xNode.Name;
GetElements(xNode);
}
}
else
{
listBox1.Items.Add(inXmlNode.Name);
}
}
You could shorten your code a little but you should start calling to start at the first element.