using System.Xml.Serialization;
public static readonly string INPUT = @"<ImportSession>
<Batch Name='MSG_SaintGobainPam_20210118' Description='SaintGobain_20210118' BatchClassName='SAINTGOBAIN - Faturas Notas' Processed='1'>
<BatchField Name='CAPALOTE' Value='0' />
<BatchField Name='NCONTENTOR' Value='0' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047804' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047804.pdf' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047842' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047842.pdf' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047843' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047843.pdf' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047849' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047849.pdf' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047853' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047853.pdf' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047854' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047854.pdf' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047855' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047855.pdf' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047860' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047860.pdf' ErrorCode='20' ErrorMessage='Illegal file format (\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047860.pdf)' />
<Document FormTypeName='DOC_SaintGobain_Faturas_Notas'>
<IndexField Name='ETIQUETA' Value='ZE80047861' />
<Page ImportFileName='\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047861.pdf' />
public static void Main()
XmlSerializer serializer = new XmlSerializer(typeof(ImportSession));
MemoryStream stream = new MemoryStream();
using StreamWriter sw = new StreamWriter(stream);
ImportSession session = (ImportSession)serializer.Deserialize(stream);
foreach( Batch batch in session.Batches )
foreach( Document doc in batch.Documents )
foreach( Page page in doc.Pages )
"BatchName='{0}', BatchDescription='{1}', BatchClassName='{2}', " +
"ImportFileName={3}, ErrorMessage={4}, HasError={5}, Processed={6}",
batch.Name, batch.Description, batch.BatchClassName,
page.ImportFileName, page.ErrorMessage, page.HasError, batch.Processed
public class ImportSession
public Batch[] Batches {get; set;}
public string Name {get; set;}
public string Description {get; set;}
public string BatchClassName {get; set;}
public bool Processed {get; set;}
public Document[] Documents {get; set;}
public string FormTypeName {get; set;}
public IndexField[] IndexFields {get; set;}
public Page[] Pages {get; set;}
public string Name {get; set;}
public string Value {get; set;}
public string ImportFileName{get; set;}
public string ErrorCode {get; set;}
public string ErrorMessage {get; set;}
public bool HasError => !string.IsNullOrWhiteSpace(ErrorMessage);