using System.Collections.Generic;
using System.Xml.Serialization;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text.RegularExpressions;
using System.Globalization;
using System.ComponentModel.DataAnnotations;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
[XmlRoot(ElementName = "DUE")]
[XmlAttribute(AttributeName = "idx")]
public string Idx { get; set; }
public string Text { get; set; }
[XmlRoot(ElementName = "RATE")]
[XmlAttribute(AttributeName = "idx")]
public string Idx { get; set; }
public decimal Text { get; set; }
[XmlRoot(ElementName = "INVOICE")]
public partial class InvoicesDTO
[XmlAttribute(AttributeName = "ID")]
public string Id { get; set; }
[XmlElement(ElementName = "STATUS")]
public string Status { get; set; }
[XmlElement(ElementName = "TOTAL")]
public decimal Total { get; set; }
[XmlElement(ElementName = "DUE")]
public List<DueDTO> Due { get; set; }
[XmlElement(ElementName = "RATE")]
public List<RateDTO> Rate { get; set; }
public partial class InvoicesDTO
public InvoicesDueDates[] InvoicesDueDates
var query = from i in Due.Select(d => d.Idx).Concat(Rate.Select(r => r.Idx)).Distinct()
join due in Due on i equals due.Idx into dueGroup
let due = dueGroup.SingleOrDefault()
join rate in Rate on i equals rate.Idx into rateGroup
let rate = rateGroup.SingleOrDefault()
select new InvoicesDueDates { Id = i, DueDate = due == null ? null : due.Text, Rate = rate == null ? (decimal?)null : rate.Text };
public class InvoicesDueDates
public string Id { get; set; }
public string DueDate { get; set; }
public decimal? Rate { get; set; }
public class RootObjectDTO
public List<InvoicesDTO> InvoicesDTO { get; set; }
public static void Test()
var root = xml.LoadFromXml<RootObjectDTO>();
var xml2 = root.GetXml(true);
Console.WriteLine("\nRe-serialized list of list of all InvoicesDueDates: ");
Console.WriteLine(root.InvoicesDTO.Select(d => d.InvoicesDueDates).ToArray().GetXml());
Console.WriteLine("\nRe-serialized {0}", root);
var xml = @"<RootObjectDTO>
<DUE idx=""1"">14.12.17</DUE>
<RATE idx=""1"">6230.00</RATE>
<DUE idx=""1"">30.11.17</DUE>
<RATE idx=""1"">1090.00</RATE>
<DUE idx=""2"">07.12.17</DUE>
<RATE idx=""2"">1090.00</RATE>
<DUE idx=""3"">14.12.17</DUE>
<RATE idx=""3"">1090.00</RATE>
public class AssertionFailedException : System.Exception
public AssertionFailedException() : base() { }
public AssertionFailedException(string s) : base(s) { }
public static class Assert
public static void IsTrue(bool value)
public static void IsTrue(bool value, string message)
throw new AssertionFailedException(message ?? "failed");
public static class XmlSerializationHelper
public static T LoadFromXml<T>(this string xmlString, XmlSerializer serial = null)
serial = serial ?? new XmlSerializer(typeof(T));
T returnValue = default(T);
using (StringReader reader = new StringReader(xmlString))
object result = serial.Deserialize(reader);
public static string GetXml<T>(this T obj, bool omitStandardNamespaces)
return obj.GetXml(null, omitStandardNamespaces);
public static string GetXml<T>(this T obj, XmlSerializer serializer = null, bool omitStandardNamespaces = false)
XmlSerializerNamespaces ns = null;
if (omitStandardNamespaces)
ns = new XmlSerializerNamespaces();
using (var textWriter = new StringWriter())
var settings = new XmlWriterSettings() { Indent = true };
using (var xmlWriter = XmlWriter.Create(textWriter, settings))
(serializer ?? new XmlSerializer(obj.GetType())).Serialize(xmlWriter, obj, ns);
return textWriter.ToString();
public static void Main()
Console.WriteLine("Environment version: " + Environment.Version);