на основе XML, модель выглядит как
[XmlRoot(ElementName = "PER")]
public class PER
{
[XmlElement(ElementName = "PER01")]
public string PER01 { get; set; }
[XmlElement(ElementName = "PER02")]
public string PER02 { get; set; }
[XmlElement(ElementName = "PER03")]
public string PER03 { get; set; }
[XmlElement(ElementName = "PER04")]
public string PER04 { get; set; }
}
[XmlRoot(ElementName = "Loop")]
public class Loop
{
[XmlElement(ElementName = "PER")]
public PER PER { get; set; }
[XmlAttribute(AttributeName = "LoopId")]
public string LoopId { get; set; }
[XmlAttribute(AttributeName = "Name")]
public string Name { get; set; }
[XmlElement(ElementName = "NM1")]
public NM1 NM1 { get; set; }
[XmlElement(ElementName = "LM")]
public LM LM { get; set; }
}
[XmlRoot(ElementName = "NM1")]
public class NM1
{
[XmlElement(ElementName = "NM101")]
public string NM101 { get; set; }
[XmlElement(ElementName = "NM102")]
public string NM102 { get; set; }
}
[XmlRoot(ElementName = "LM")]
public class LM
{
[XmlElement(ElementName = "LM01")]
public string LM01 { get; set; }
[XmlElement(ElementName = "LM02")]
public string LM02 { get; set; }
}
[XmlRoot(ElementName = "Type")]
public class Type
{
[XmlElement(ElementName = "Loop")]
public List<Loop> Loop { get; set; }
}
Вот логарифм c до DeSerialize
XML для объекта
XmlSerializer serializer = new XmlSerializer(typeof(Type));
string xml = File.ReadAllText("XMLFile3.xml");
using (TextReader reader = new StringReader(xml))
{
var results = (Type)serializer.Deserialize(reader);
foreach (var item in results.Loop)
{
Console.WriteLine($"{item.LoopId} {item.Name}");
if (item.PER != null)
{
Console.WriteLine($"PER:{Regex.Replace(item.PER.PER01, @"\s+", "")}-{Regex.Replace(item.PER.PER02, @"\s+", "")}-{Regex.Replace(item.PER.PER03, @"\s+", "")}-{Regex.Replace(item.PER.PER04, @"\s+", "")}");
}
if (item.NM1 != null)
{
Console.WriteLine($"NM1:{Regex.Replace(item.NM1.NM101, @"\s+", "")}-{Regex.Replace(item.NM1.NM102, @"\s+", "")}");
}
if (item.LM != null)
{
Console.WriteLine($"LM:{Regex.Replace(item.LM.LM01, @"\s+", "")}-{Regex.Replace(item.LM.LM02, @"\s+", "")}");
}
}
}
ВЫХОД
2100A MEMBER NAME
PER:IP--HP-6235834409
2100C MEMBER MAILING ADDRESS
NM1:31-1
2100G RESPONSIBLE PERSON
PER:IP--HP-6235834409
LM:RP-