I have an XML File and i would like to iterate though each child node gathering information.
Here is my C# code it only picks up one node, the FieldData i would like
To iterate through each and every child node, sub-child node and so on, We have to use Recursion
. In case someone have the same requirement as I had, I achieved this something like below -
public string ReadAllNodes(XmlNode node)
{
if (node.ChildNodes.Count > 0)
{
foreach (XmlNode subNode in node)
{
//Recursion
ReadAllNodes(subNode);
}
}
else //Get the node value.
{
finalText = finalText + node.InnerText + System.Environment.NewLine;
}
return finalText;
}