Nick Kahn
Nick Kahn

Reputation: 20078

What is the best way of removing the duplicates in XMLNode

What is the best way of removing the duplicates in XMLNode, below is my code.

XmlDocument xdoc = new XmlDocument();//xml doc used for xml parsing

    xdoc.Load(url);

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xdoc.NameTable);
nsmgr.AddNamespace("content", "sitename.xsd");

var topicNodes = xdoc.SelectNodes("//content:Topic", nsmgr);

foreach (XmlNode node in topicNodes)
{
    string topic = node.Attributes["TopicName"].Value;
    //adding topic name to dropdwonlist
    dropdownlist.items.add(new listitem(topic);
}
dropdownlist.databind();

Upvotes: 0

Views: 239

Answers (1)

bryanmac
bryanmac

Reputation: 39306

One option would be to create a HashSet and as you loop check if in HashSet ... if not, add to the HashSet and the dropdownlist.

You would use HashSet - here's the Add and Contains:

http://msdn.microsoft.com/en-us/library/bb356440.aspx

Upvotes: 1

Related Questions