XmlDocument doc = new XmlDocument();//Carrega em DOC o arquivo XML, o caminho pode ser uma url que poderia estar em qualquer site
//ou pode ser o caminho físico da sua área, por exemplo E:\home\SeuLoginFtp\Web\ARQUIVO.xml// doc.Load("http://www.SEUDOMINIO.com.br/ARQUIVO.xml");doc.Load("http://localhost:51000/websabat/xml/arquivo.xml");//Cria uma instância XmlElement na qual atribuímos a raiz do documento
XmlElement Elem = doc.DocumentElement;//Percorre todos os elementos filhos que existem no elemento raizLabel1.Text +=
***********
for(int i=0;i<Elem.ChildNodes.Count;i++)
{
//Imprime o valor do elemento encontrado dentro do elemento Filho atual
Label1.Text += "Todo Linha: " + Elem.ChildNodes.Item(i).InnerText + "<br>";
//Percorre todos os elementos que estiverem dentro do elemento filho atual
Label1.Text += "Quantidade de Nós Filhos: " + Elem.ChildNodes.Item(i).ChildNodes.Count + "<br>";
for (int a = 0; a < Elem.ChildNodes.Item(i).ChildNodes.Count; a++)
{
//Imprime o valor do elemento encontrado dentro do elemento Filho atual
Label1.Text += "Nó Filho " + a + ": " + Elem.ChildNodes.Item(i).ChildNodes.Item(a).InnerText + "<br>";
for (int j = 0; j < Elem.ChildNodes.Item(i).ChildNodes.Item(a).ChildNodes.Count; j++)
{
Label1.Text += "Nó Neto " + j + ": " + Elem.ChildNodes.Item(i).ChildNodes.Item(a).ChildNodes.Item(j).InnerText + "<br>";
}
}
}
*******
Label1.Text += "Nota Fiscal Número: " + Elem.ChildNodes.Item(0).ChildNodes.Item(0).InnerText + "<br>";
Label1.Text += "Data: " + Elem.ChildNodes.Item(0).ChildNodes.Item(1).InnerText + "<br>";
Label1.Text += "Cliente:" + Elem.ChildNodes.Item(0).ChildNodes.Item(2).InnerText + "<br>";
**********
TableRow tr1 = new TableRow();
TableCell tc1 = new TableCell();
tc1.Text = "Nota Fiscal Número " + Elem.ChildNodes.Item(0).ChildNodes.Item(0).InnerText ;
tr1.Controls.Add(tc1);
Table2.Rows.Add(tr1);
TableRow tr2 = new TableRow();
TableCell tc2 = new TableCell();
tc2.Text = "Data " + Elem.ChildNodes.Item(0).ChildNodes.Item(1).InnerText;
tr2.Controls.Add(tc2);
Table2.Rows.Add(tr2);
TableRow tr3 = new TableRow();
TableCell tc3 = new TableCell();
tc3.Text = "Cliente " + Elem.ChildNodes.Item(0).ChildNodes.Item(2).InnerText;
tr3.Controls.Add(tc3);
Table2.Rows.Add(tr3);
************
for (int k =4; k < 7; k++)
{
TableRow trow = new TableRow();
int limite1 = Elem.ChildNodes.Item(0).ChildNodes.Item(k).ChildNodes.Count;
Label1.Text += limite1+"<br>";
for (int n = 0; n < limite1; n++)
{
TableCell tcell = new TableCell();
tcell.Text = Elem.ChildNodes.Item(0).ChildNodes.Item(k).ChildNodes.Item(n).InnerText;
trow.Controls.Add(tcell);
}
Table1.Rows.Add(trow);
}
Nenhum comentário:
Postar um comentário