@sollaholla I think I did what you're looking for. It's a little tricky because you said the structure could be anything, so you'll need to specify some parameters at the top to adjust it for another XML file. You can turn this code into a function and have those parameters be passed into the function to modularize it:
using System.Xml;
// Load your XML
XmlDocument doc = new XmlDocument();
doc.Load("input.xml");
// XPath for the parent node of your list to filter
String filterParent = "CWeaponInfoBlob/SlotNavigateOrder/Item/WeaponSlots";
// Node name that you're going to filter against
String filterNodeName = "Entry";
// Node value that you're looking for
String filterNodeValue = "STUNGUN";
// Get a reference to the parent node of the list
XmlNode itemsParent = doc.SelectSingleNode(filterParent);
// Clone the parent node and empty it out
XmlNode filteredParent = itemsParent.Clone();
filteredParent.RemoveAll();
// Iterate over all the children in the parent node
foreach (XmlElement item in itemsParent.ChildNodes) {
// If the node name you're looking for exists and its text contains your filter value
if (item[filterNodeName] != null && item[filterNodeName].InnerText.Contains(filterNodeValue)) {
// Add it to the filtered parent
filteredParent.AppendChild(item);
}
}
// Get a reference to the parent of the parent node and empty it out
XmlNode filteredInsertNode = itemsParent.ParentNode;
filteredInsertNode.RemoveChild(itemsParent);
// Insert your new filtered list
filteredInsertNode.AppendChild(filteredParent);
// Print out the XML, write to file, etc...
Console.WriteLine(doc.OuterXml);