Good morning, I have the following XML code.
<?xml version="1.0" encoding="utf-8"?>
<Regras>
<Regra Id="1" ExtensaoArquivo=".RET" PastaOrigem="C:\Nova pasta\" PastaDestino="C:\Nova pasta (4)\">
<depara IdRegra="1" Codigo="1" De="FORN" Para="Fornecedor"/>
<depara IdRegra="1" Codigo="2" De="3XKP" Para="AEFL"/>
<depara IdRegra="1" Codigo="3" De="MOV" Para="Retorno"/>
</Regra>
<Regra Id="2" ExtensaoArquivo=".RET" PastaOrigem="C:\Nova pasta\" PastaDestino="C:\Nova pasta (2)\">
<depara IdRegra="2" Codigo="1" De="FORN" Para="Fornecedor"/>
<depara IdRegra="2" Codigo="2" De="4I8O" Para="Loja"/>
<depara IdRegra="2" Codigo="3" De="MOV" Para="Retorno"/>
</Regra>
</Regras>
I would like to load its data into an array, and I need to bring all the information contained in the xml to the array.
private void BuscarPorArquivosToolStripMenuItem_Click(object sender, EventArgs e)
{
LerArquivoXml arquivos = new LerArquivoXml("Teste", "Config.xml");
XmlDocument xmlDocument = new XmlDocument();
Regras criterios = new Regras();
xmlDocument.Load(criterios.GetCaminhoRegras().ToString());
XmlNode raiz = xmlDocument.SelectSingleNode(@"/Regras");
//dgvListagemArquivos.Rows.Clear();
foreach (XmlNode no in raiz.ChildNodes)
{
string Id = no.Attributes["Id"].Value;
string ExtensaoArquivo = no.Attributes["ExtensaoArquivo"].Value;
string PastaOrigem = no.Attributes["PastaOrigem"].Value;
string PastaDestino = no.Attributes["PastaDestino"].Value;
}
XmlNode filho = xmlDocument.SelectSingleNode(@"/Regras/Regra");
var ele = System.Xml.Linq.XElement.Load(criterios.GetCaminhoRegras().ToString());
int cont = filho.SelectNodes(@"/Regras/Regra/depara").Count;
string[,] depara = new string[cont*4, 4];
for (int l = 0; l < cont*cont;)
{
foreach (XmlNode child in filho.ChildNodes)
{
string IdRegra = child.Attributes["IdRegra"].Value;
string Codigo = child.Attributes["Codigo"].Value;
string De = child.Attributes["De"].Value;
string Para = child.Attributes["Para"].Value;
for (int c = 0; c < 4; c++)
{
depara[l, c] = IdRegra.ToString();
depara[l, c + 1] = Codigo.ToString();
depara[l, c + 2] = De.ToString();
depara[l, c + 3] = Para.ToString();
c = 4;
l += 1;
}
}
}
}