开发者

Removing multiple occurences of a node in an XMLNodeList or combobox

My objective is to search an XML document for particutar nodeS and populate a combobox with those nodes' Id's. I can do this by using the folloing:

        XmlNodeList nodeList = doc.SelectNodes("//开发者_StackOverflowNodeA");
        foreach (XmlNode node in nodeList)
     {
         comboBox1.Items.Add(node.Attributes["id"].Value);
     }

My problem is this. There are multiple occurances of the Xpath "//NodeA" with the same ID attribute. Therefore I end up populating the combobox with multiple occurances of these node IDs. I only want one of each in the combo box.

Can someone please assist?


if(!comboBox1.Items.Contains(node.Attributes["id"].Value))
{
 comboBox1.Items.Add(node.Attributes["id"].Value);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜