I’m trying to Create a login form, and registration form.
My registration form is complete,
by registrating an XML file is created with this code,
private void newregisterBtn_Click(object sender, EventArgs e)
{
if (usernameTxb.Text == null && nameTxb.Text == null && ageTxb.Text == null && countryTxb.Text == null && passwordTxb.Text == null)
{
usernLbl.ForeColor = Color.Red;
nameLbl.ForeColor = Color.Red;
ageLbl.ForeColor = Color.Red;
countryLbl.ForeColor = Color.Red;
passwordLbl.ForeColor = Color.Red;
// this doesn't work
}
else
{
string filename = @"C:\\testxml\\" + usernameTxb.Text + ".xml";
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("Login");
XmlElement id = doc.CreateElement("id");
id.SetAttribute("userName", usernameTxb.Text);
id.SetAttribute("passWord", passwordTxb.Text);
XmlElement name = doc.CreateElement("Name");
name.InnerText = nameTxb.Text;
XmlElement age = doc.CreateElement("Age");
age.InnerText = ageTxb.Text;
XmlElement Country = doc.CreateElement("Country");
Country.InnerText = countryTxb.Text;
id.AppendChild(name);
id.AppendChild(age);
id.AppendChild(Country);
root.AppendChild(id);
doc.AppendChild(root);
doc.Save(filename);
MessageBox.Show("Created SuccesFully!");
this.Close();
}
}
Now that’s not to important, on my second form (login form), i just got an ‘usernameTxb’ a ‘passwordTxb’ a ‘loginBtn’ and a ‘registerBtn’.
Now i want a piece of code that finds and see if the usernameTxb and passwordTxb are equal to the info writen into the xml file.
here is some xml code.
<Login>
<id userName="Username" passWord="password">
<Name>Joshua Maerten</Name>
<Age>21</Age>
<Country>Belgium</Country>
</id>
</Login>
If you can use LINQ for XML parsing this should conceptually work based on your XML: