// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Xml; namespace E { public class Program { public static void Main(string[] args) { string s = @" SALE1 1234 SALE2 1234 REFUND1 1234 "; Console.WriteLine(s); XmlDocument doc = new XmlDocument(); doc.LoadXml(s); //XmlNodeList net = doc.SelectNodes("//transaction[starts-with(documentNumber,'SALE') and count(//transaction[documentNumber=concat('REFUND',substring-after(?/documentNumber,'SALE'))])=0]"); XmlNodeList net = doc.SelectNodes("//transaction[starts-with(documentNumber,'SALE')]"); foreach(XmlElement elm in net) { if(doc.SelectSingleNode(string.Format("//transaction[documentNumber='{0}']", elm.FirstChild.FirstChild.Value.Replace("SALE", "REFUND"))) == null) { Console.WriteLine(elm.OuterXml); } } } } }