The error i get is Daya at the root level is invalid. Line 1, position 1.
using System;
using System.Xml;
using System.IO;
namespace XmlReaderConsoleAPP
{
class Program
{
static void Main()
{
XmlDocument xml = new XmlDocument();
xml.LoadXml("c:\\SaintGobain_Pam_20210118.xml");
string _byteOrderMarkUtf8 =
Enconding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (xml.StartWith(_byteOrderMarkUtf8))
{
var lastIndexOfUtf8 = _byteOrderMarkUtf8.Length - 1;
xml = xml.Remove(0, _byteOrderMarkUtf8.Length - 1);
}
XmlNodeList xnLista = xml.SelectNodes("/Batches/Batch/BatchFields/BatchField/Documents/Document/IndexFields/IndexField/Pages/Page");
foreach(XmlNode xn in xnLista)
{
string formulario = xn["FormTypeName"].InnerText;
string Value = xn["Value"].InnerText;
string FileName = xn["ImportFileName"].InnerText;
Console.WriteLine("Formulário: {0}", formulario, "Value: {1} ", Value, "FilePath: {2}", FileName);
}
}
}
}
And the XML contents are
<ImportSession>
<Batches>
<Batch Name="MSG_SaintGobainPam_20210118" Description="SaintGobain_20210118"
BatchClassName="SAINTGOBAIN - Faturas Notas" Processed="1">
<BatchFields>
<BatchField Name="CAPALOTE" Value="0" />
<BatchField Name="NCONTENTOR" Value="0" />
</BatchFields>
<Documents>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047804" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047804.pdf" />
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047842" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047842.pdf" />
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047843" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047843.pdf" />
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047849" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047849.pdf"/>
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047853" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047853.pdf" />
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047854" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047854.pdf" />
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047855" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047855.pdf" />
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047860" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047860.pdf"/>
ErrorCode="20" ErrorMessage="Illegal file format
(\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047860.pdf)" />
</Pages>
</Document>
<Document FormTypeName="DOC_SaintGobain_Faturas_Notas">
<IndexFields>
<IndexField Name="ETIQUETA" Value="ZE80047861" />
</IndexFields>
<Pages>
<Page
ImportFileName="\\umm\c$\acxmlaid\SaintGobain\20210118\ZE80047861.pdf"/>
</Pages>
</Document>
</Documents>
</Batch>
Im asking this because i couldnt find a answer to my question but if there is please link it in the answers. XML FILE is now added to the post as you can see. I really dont know why it keeps happening but ye hope you guys can help.