Ajuda XML Nfe

20/06/2012

0

Bom dia a todos,

Estou pegando os dados do meu XML com o código abaixo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using XML.BLL;
using System.Data;


namespace XML
{
    public partial class XML : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnVisualizar_Click(object sender, EventArgs e)
        {
            if (FileUpload1.FileContent != null)
            {
                btnGravar.Visible = true;

                XDocument xmlFile = XDocument.Load(FileUpload1.FileContent);

                #region [ Funcional ]

                var Consulta = from a in xmlFile.Descendants()
                               select a;

                foreach (var item in Consulta)
                {


                    if (item.Name.LocalName == idLote)
                    {
                        Label2.Visible = true;
                        txtidLote.Visible = true;
                        String idLote = item.Value;
                        txtidLote.Text = idLote;
                    }

                    if (item.Name.LocalName == cUF)
                    {
                        Label3.Visible = true;
                        txtcUF.Visible = true;
                        String cUF = item.Value;
                        txtcUF.Text = cUF;
                    }

                    if (item.Name.LocalName == cNF)
                    {
                        Label4.Visible = true;
                        txtcNF.Visible = true;
                        String cNF = item.Value;
                        txtcNF.Text = cNF;
                    }

                    if (item.Name.LocalName == natOp)
                    {
                        Label5.Visible = true;
                        txtnatOp.Visible = true;
                        String natOp = item.Value;
                        txtnatOp.Text = natOp;
                    }

                    if (item.Name.LocalName == indPag)
                    {
                        Label6.Visible = true;
                        txtindPag.Visible = true;
                        String indPag = item.Value;
                        txtindPag.Text = indPag;
                    }

                    if (item.Name.LocalName == mod)
                    {
                        Label7.Visible = true;
                        txtmod.Visible = true;
                        String mod = item.Value;
                        txtmod.Text = mod;
                    }

                    if (item.Name.LocalName == serie)
                    {
                        Label8.Visible = true;
                        txtserie.Visible = true;
                        String serie = item.Value;
                        txtserie.Text = serie;
                    }

                    if (item.Name.LocalName == nNF)
                    {
                        Label9.Visible = true;
                        txtnNF.Visible = true;
                        String nNF = item.Value;
                        txtnNF.Text = nNF;
                    }

                    if (item.Name.LocalName == dEmi)
                    {
                        Label10.Visible = true;
                        txtdEmi.Visible = true;
                        String dEmi = item.Value;
                        txtdEmi.Text = dEmi;
                    }

                    if (item.Name.LocalName == dSaiEnt)
                    {
                        Label11.Visible = true;
                        txtdSaiEnt.Visible = true;
                        String dSaiEnt = item.Value;
                        txtdSaiEnt.Text = dSaiEnt;
                    }

                    if (item.Name.LocalName == tpNF)
                    {
                        Label13.Visible = true;
                        txttpNF.Visible = true;
                        String tpNF = item.Value;
                        txttpNF.Text = tpNF;
                    }

                #endregion


                }
            }
        }


Até ai está tudo funcionando bem, o problema começa quando preciso pegar os dados que estão dentro das tags


<det nItem=1></det>

<infNFe versao=2.00 Id=NFe3512035340254100010255000000007807000000000></infNFe>


Preciso pegar o nItem e o Id, mas dessa forma não consigo porque da erro.


Obrigado!
Gabriella Candelaria

Gabriella Candelaria

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar