c# xml function to check whether a string is equal to a xml attribute, to add selected combobox item
        Posted  
        
            by fuch
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by fuch
        
        
        
        Published on 2010-05-22T20:16:06Z
        Indexed on 
            2010/05/22
            20:20 UTC
        
        
        Read the original article
        Hit count: 178
        
i want to check the combobox.selecteditem.tostring() on combobox select in a given xml with several nodes, where each one has an attribute called "name"
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        textBox1.AppendText(nameAttributeCheck(comboBox1.SelectedItem.ToString()));
    }
    catch { 
    }
}
private string nameAttributeCheck(string a)
{
    XmlDocument doc = new XmlDocument();
    doc.Load("armor.xml");
    XmlElement root = doc.DocumentElement;
    XmlNodeList items = root.SelectNodes("/items");
    String result = null;
    try
    {
        foreach (XmlNode item in items)
        {
                if (string.Equals(a, item.Attributes["name"].InnerText.ToString()))
                {
                    result += item.Attributes["picture"].InnerText.ToString();
                }
        }
    }
    catch
    {
    }
    return result;
}
each time i try it, nothing happens
© Stack Overflow or respective owner