public static void Create(string ModelXML, string outFile) { XElement doc = XElement.Load(ModelXML); XNamespace ns = doc.GetDefaultNamespace(); var ItemModel = (from item in doc.Descendants(ns + "TcTypeConstantAttach") join IM in doc.Descendants(ns + "TcTypeConstantAttach") on item.Attribute("typeName").Value equals IM.Attribute("typeName").Value join IRM in doc.Descendants(ns + "TcTypeConstantAttach") on item.Attribute("value").Value equals IRM.Attribute("typeName").Value where item.Attribute("constantName").Value == "ItemRevision" && IM.Attribute("constantName").Value == "MasterForm" && IRM.Attribute("constantName").Value == "MasterForm" select new { Item = item.Attribute("typeName").Value, ItemRevision = item.Attribute("value").Value, IM = IM.Attribute("value").Value, IRM = IRM.Attribute("value").Value }).OrderBy(x => x.Item); string[] PrintModel = ItemModel.Select(x => String.Join(",", new Object[] { x.Item, x.ItemRevision, x.IM, x.IRM })).ToArray(); File.WriteAllLines(outFile, PrintModel); }