dimanche 28 juin 2015

How to get index by using XmlDocument functions? C#

I created a C# Web Form Application, and I want to get index from specific object. This is what I have for now. In this exercise, I want to input login name and password in order to get info from that specific person. Duplicated name/password is allowed. What I can think of is get index from nodes, and then use XmlNodeList info = reader.GetElementsByTagName("Info"); and textBox1.Text = root.GetElementsByTagName("Info")[index].InnerText; I need to find that specific index, but I feel a little bit confuse about that. Hope someone can give me any suggestions, and new idea on how to do it, thank you!

private int GetIndex(string loginname, string password)
{
    reader = new XmlDocument();
    reader.Load(@filepath);
    XmlNodeList loginN = reader.GetElementsByTagName("Loginname");
    XmlNodeList Pass = reader.GetElementsByTagName("Password");
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<Authentication>
  <User xmlns="">
    <Loginname>Admin</Loginname>
    <Password>232</Password>
    <Info>Hello, I'm first person</Info>
  </User>
  <User xmlns="">
    <Loginname>Admin</Loginname>
    <Password>4445</Password>
    <Info>Hello, I'm second person</Info>
  </User>
</Authentication>

Aucun commentaire:

Enregistrer un commentaire