Seems simple enough using
LINQ to XML[
^]:
string pin0 = " value0 ", pin1 = null, pin2 = " value2 ", pin3 = null;
XDocument document = XDocument.Load("load.xml");
var select = doc.Descendants("Select").Select(s => new
{
val = (string)s.Attribute("val"),
pins = s.Elements("Pin").ToDictionary(p => (int)p.Attribute("val"), p => (string)p),
});
if (pin0 != null)
{
select = select.Where(s => s.pins.TryGetValue(0, out var p0) && p0 == pin0);
}
if (pin1 != null)
{
select = select.Where(s => s.pins.TryGetValue(1, out var p1) && p1 == pin1);
}
if (pin2 != null)
{
select = select.Where(s => s.pins.TryGetValue(2, out var p2) && p2 == pin2);
}
if (pin3 != null)
{
select = select.Where(s => s.pins.TryGetValue(3, out var p3) && p3 == pin3);
}
NB: The values need to match exactly. Your source XML document has spaces around the values, so the filter values need to have spaces around the values. If you want to ignore the spaces, you'll need to trim the values from the XML document.