Hi.
The reason it searches only the first node is because you need to specify in which node to search. Currently you only specify the upper most node sets with
xdoc.SelectSingleNode("Users/User/Password");
to search for subnodes, you need to use
subnode.SelectSingleNode("Users/User/Password");
If you know the names of the nodes, this becomes easy. If you don't, this becomes a bit more tricky. I have a recursive method and an override for it that could help you. It's not the most elegant code there is but it does solve your problem.
private XmlNode checkNode(XmlDocument xdoc, string nodeName)
{
XmlNode node;
if(xdoc.SelectSingleNode(nodeName) != null)
{
node = xdoc.SelectSingleNode(nodeName);
}
else
{
foreach(XmlNode currentNode in xdoc.DocumentElement.ChildNodes)
{
node = checkNode(currentNode, nodeName);
if(node != null)
{
break;
}
}
}
return node;
}
private XmlNode checkNode(XmlNode parentNode, string nodeName)
{
XmlNode node;
if(currentNode.SelectSingleNode(nodeName) != null)
{
node = xdoc.SelectSingleNode(nodeName);
}
else
{
foreach(XmlNode currentNode in parentNode.DocumentElement.ChildNodes)
{
node = checkNode(currentNode, nodeName);
if(node != null)
{
break;
}
}
}
return node;
}
Here is how you would do the check (Example):
string username = UsernameTextbox.Text;
string password = PasswordTextbox.Text;
string permission = PermissionComboBox.SelectedItem.ToString();
if (username == checkNode(xdoc, "usernameNodeName").InnerText
&& password == checkNode(xdoc, "passwordNodeName").InnerText
&& permission == checkNode(xdoc, "permissionNodeName").InnerText)
{
MessageBox.Show("Login Details Match");
Menu MenuPage = new Menu();
MenuPage.Show();
this.Hide();
}