Effizientes Entfernen doppelter XML-Elemente in c #

Ich habe einige XML-Dateien, die viele doppelte Einträge wie diese enthalten.

<annotations>
  <annotation value=",Clear,Outdoors" eventID="2">
    <image location="Location 1" />
    <image location="Location 2" />
    <image location="Location 2" />
  </annotation>

  <annotation value=",Not a problem,Gravel,Shopping" eventID="2">
    <image location="Location 3" />
    <image location="Location 4" />
    <image location="Location 5" />
    <image location="Location 5" />
    <image location="Locat,ion 5" />
  </annotation>
</annotations>

Ich möchte die doppelten Elemente in jedem der untergeordneten Elemente entfernen. Die Art und Weise, wie ich das angegangen bin, besteht darin, alle Elemente in eine Liste zu kopieren und sie dann zu vergleiche

 foreach (var el in xdoc.Descendants("annotation").ToList())
   {
      foreach (var x in el.Elements("image").Attributes("location").ToList())
       {
           //add elements to a list
       }
   }

uf halbem Weg stellte ich fest, dass dies sehr ineffizient und zeitaufwändig ist. Ich bin ziemlich neu in XML und habe mich gefragt, ob es in C # integrierte Methoden gibt, mit denen ich Duplikate entfernen kan

Ich habe versucht mit

if(!x.value.Distinct()) // can't convert collections to bool
    x.Remove();

Aber das funktioniert nicht, auch nicht

if(x.value.count() > 1) // value.count returns the number of elements.
   x.Remove()

Antworten auf die Frage(3)

Ihre Antwort auf die Frage