I have a method in C# that finds a node with name node_name in node list arg, and returns the value of found node (assuming there's only one node with such name). If no such nodes are found, it should return an empty string.
public string get_nodes_value(XmlNodeList arg, string node_name)
{
foreach (XmlNode arg_node in arg)
{
if (!arg_node.HasChildNodes)
{
if (String.Compare(arg_node.ParentNode.Name, node_name) == 0)
{
return arg_node.Value;
}
}
else
{
get_nodes_value(arg_node.ChildNodes, node_name);
}
}
return "";
}
The code above always returns an empty string. What did I miss here?