title: Remove Duplicates in Xml Document
body: <p>I have two XML documents that contain a list of products. Currently, we just copy one and paste it into the other and create a new merged document, however, these two files have a number of the same products so I need to merge the two <strong>and remove the duplicates</strong>. My XML documents are in the following structure:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
      &lt;table&gt;
         &lt;row Code="HST15154"
         ProductName="test"
         ProductName_EN=""
         Description_EN=""
         Price=""
         ProductType1="HST ACCESSORIES"
         ProductType2="SAM - Accessories"
         ProductCategory="Accessories"
         Remarks=""
         /&gt;
      &lt;/table&gt;
  </code></pre>
  
  <p>I found some code that I tried to alter to my needs <a href="https://social.msdn.microsoft.com/Forums/en-US/e4c64446-3cd3-4f3f-bf33-f4da9ed0583c/deleting-the-duplicate-nodes-of-xml-file-using-c?forum=csharplanguage" rel="nofollow noreferrer">here</a>. I need only one of each "Code."</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Xml;
  
  namespace HST_Merging_Console_App
  {
      public class Program
      {
          public void Main(string[] args)
          {
              //open the xml document
              XmlDocument doc = new XmlDocument();
              doc.LoadXml("U:\\Documents (U)\\XML Merging Tool\\productcollection_us.xml");
  
              //select all row elements
              XmlNodeList parts = doc.SelectNodes("/row");
  
              //create a list of previously seen P/Ns
              List&lt;string&gt; PartsSeen = new List&lt;string&gt;();
  
              foreach(XmlNode part in parts)
              {
                  string partNumber = part.Attributes["Code"].Value;
  
                  //for each part, see if we have seen it before, if it is in the list,
                  //remove the part element from the parent to which it belongs
                  if (PartsSeen.Contains(partNumber))
                      part.ParentNode.RemoveChild(part);
                  else
                      PartsSeen.Add(partNumber);
              }
              Console.Read();
              doc.Save("U:\\Documents (U)\\XML Merging Tool\\productcollection_merged.xml");
          }
      }
  }
  </code></pre>
  
  <p>I'm receiving a couple errors when I run this:</p>
  
  <p><strong>CS1061</strong> - 'XmlDocument' does not contain a definition for 'SelectNodes' and no extension method 'SelectNodes' accepting a first argument of type 'XmlDocument' could be found (are you missing a using directive or an assembly reference?) (Line 16)</p>
  
  <p><strong>CS1503</strong> - Argument 1: cannot convert from 'string' to 'System.IO.Stream' (Line 33)</p>
  
  <p>Another approach I've considered is to take the first file and load into a dataset then take the second file and load it into a 2nd dataset. Then loop through the 2nd dataset searching for the Code in the 1st dataset, if found update the row, if not, add the row. </p>
  
  <p><em>This is my first time working with C# and trying to create a program to run on a server</em>. Any help and/or advice is greatly appreciated.</p>