// 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.Linq; using System.Xml.Linq; namespace E { public class Program { public static void Main(string[] args) { XDocument doc = XDocument.Load(@"C:\fileparser.xml"); var q = from f in doc.Descendants("Field") where (decimal) f.Parent.Attribute("version") == 1.2M select f; foreach(var f in q) { Console.WriteLine("field name = " + f.Attribute("name").Value); if(f.Attribute("required") != null) { Console.WriteLine("field required = " + f.Attribute("required").Value); } var q2 = from r in f.Descendants("Rule") select r; foreach(var r in q2) { Console.WriteLine("rule type = " + r.Attribute("type").Value); if(r.Element("RegExp") != null) { Console.WriteLine("rule regexp = " + r.Element("RegExp").Value); } if(r.Elements("Values") != null) { foreach(XElement vals in r.Elements("Values")) { Console.WriteLine("rule values = " + vals.Value); } } } } } } }