Make a query on a specific node of an XML file in C #

2

I have a login system in C # and a following XML file:

    <?xml version="1.0"?>
<Usuarios>
    <Usuario>
        <User_ID>001</User_ID>
        <Password>010309</Password>
        <Password_Change_Date>00/00/00</Password_Change_Date>
        <User_Login>admteste</User_Login>
        <User_RG>00000002</User_RG>
        <User_Status>Normal</User_Status>
        <User_Profile>4</User_Profile>
    </Usuario>
    <Usuario>
        <User_ID>002</User_ID>
        <Password>01234</Password>
        <Password_Change_Date>01/10/2019</Password_Change_Date> 
        <User_Login>pbteste</User_Login>
        <User_RG>00000005</User_RG>
        <User_Status>Inicial</User_Status>
        <User_Profile>3</User_Profile>
    </Usuario>  
    <Usuario>
        <User_ID>003</User_ID>
        <Password>01234</Password>
        <Password_Change_Date>21/1/2013</Password_Change_Date>
        <User_Login>pbteste2</User_Login>
        <User_RG>00000023</User_RG>
        <User_Status>Bloqueado</User_Status>
        <User_Profile>3</User_Profile>
    </Usuario>
</Usuarios>

In my system, when the user presses the Login button, I need to check in this XML if the login name exists in this file and if the password is according to the user, how can I do it by reading only the User_Login and Password nodes? Thanks

    
asked by anonymous 28.10.2017 / 21:59

1 answer

2

Follow the XPATH example to check for a Usuario node with User_Login and Password :

string usuario = "pbteste";
string senha = "01234x";

XmlNodeList nodeList
    = doc.SelectNodes("//Usuario[User_Login[text()='" + usuario + "'] and Password[text()='" + senha + "']]");

if(nodeList.Count == 0)
    MessageBox.Show("Usuário e/ou Senha estão incorretos");
    
29.10.2017 / 00:45