// 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.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace E { public class Program { public static void Main(string[] args) { string s = @" 1 xx@xx.com 2 yy@xx.com 3 xx@xx.com "; XDocument doc = XDocument.Parse(s); StringBuilder res = new StringBuilder(); res.Append("" + Environment.NewLine); IEnumerable elements = doc.Root.Elements("user").Where(n => n.Element("email").Value.Contains("xx@")); foreach (XNode node in elements) { res.Append(node.ToString() + Environment.NewLine); } res.Append("" + Environment.NewLine); Console.WriteLine(res.ToString()); Console.WriteLine("" + Environment.NewLine + string.Join(Environment.NewLine, doc.Root.Elements("user").Where(n => n.Element("email").Value.Contains("xx@")).Select(n => n.ToString()).ToArray()) + Environment.NewLine); } } }