// 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 Addresse { private string vejnavn; private string vejnr; private string postnr; private string postby; public Addresse() : this("", "", "", "") { } public Addresse(string vejnavn, string vejnr, string postnr, string postby) { this.vejnavn = vejnavn; this.vejnr = vejnr; this.postnr = postnr; this.postby = postby; } public string Vejnavn { get { return vejnavn; } set { vejnavn = value; } } public string Vejnr { get { return vejnr; } set { vejnr = value; } } public string Postnr { get { return postnr; } set { postnr = value; } } public string Postby { get { return postby; } set { postby = value; } } public override string ToString() { return vejnavn + " " + vejnr + "\r\n" + postnr + " " + postby; } } public class Program { public static void Main(string[] args) { XElement addresser = XElement.Load(@"C:\addresser.xml"); XElement postdistrikter = XElement.Load(@"C:\postdistrikter.xml"); var alla = from a in addresser.Elements("addresse") join p in postdistrikter.Elements("postdistrikt") on a.Element("postnr").Value equals p.Element("postnr").Value select new Addresse(a.Element("vejnavn").Value, a.Element("vejnr").Value, a.Element("postnr").Value, p.Element("postby").Value); foreach(Addresse a in alla) { Console.WriteLine(a); } } } }