using System.Collections.Generic;
using System.Xml.Serialization;
public static void Main()
<Doc xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<Header DocNumber=""1"" Description=""Desc1""></Header>
<Pos Id=""1"" Name=""Pos1""></Pos>
<Pos Id=""2"" Name=""Pos2""></Pos>
<Doc xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
<Header DocNumber=""2"" Description=""Desc2""></Header>
<Pos Id=""3"" Name=""Pos3""></Pos>
<Pos Id=""4"" Name=""Pos4""></Pos>
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Doc));
XDocument xDoc = XDocument.Parse(xml);
var cdataSections = xDoc.XPathSelectElements("/Docs/Doc/Content")
.Select(x => (Doc)xmlSerializer.Deserialize(new StringReader(x.Value)))
foreach (var section in cdataSections)
Console.WriteLine(section);
public Header Header { get; set; }
[XmlArrayItem(typeof(Pos), ElementName = "Pos")]
public List<Pos> Poss { get; set; }
public override string ToString()
StringBuilder sb = new StringBuilder();
sb.AppendLine(String.Format("Header: {0}", Header));
foreach (var pos in Poss)
sb.AppendLine(String.Format("Pos: {0}", pos));
public int DocNumber { get; set; }
public string Description { get; set; }
public override string ToString()
return String.Format("DocNumber: {0}, Description: {1}", DocNumber, Description);
public int Id { get; set; }
public string Name { get; set; }
public override string ToString()
return String.Format("Id: {0}, Name: {1}", Id, Name);