using System;
using System.Collections.Generic;
using System.Xml;
public class Test
{
public static void Main()
{
var document = new XmlDocument();
document.LoadXml(@"
Success
Install period
failure
uninstall period
failure
discard period
Done
Got Output
");
Dictionary used = new Dictionary();
var allNodes = document.SelectNodes("Root/Main");
for (int i = allNodes.Count - 1; i >= 0; i--)
{
var name = ((XmlElement)allNodes[i]).GetAttribute("Name");
if (used.ContainsKey(name))
{
allNodes[i].ParentNode.RemoveChild(allNodes[i]);
}
else
{
used.Add(name, true);
}
}
Console.WriteLine(document.OuterXml);
}
}