Ver Mensaje Individual
  #4 (permalink)  
Antiguo 30/01/2014, 15:45
alexg88
 
Fecha de Ingreso: abril-2011
Mensajes: 1.342
Antigüedad: 13 años
Puntos: 344
Respuesta: como agregar mas nodos "concepto" en un ciclo for??

Buenas,

La forma sería sacar el nodo de conceptos fuera y luego utilizar un bucle (for, foreach, etc):

Código C++:
Ver original
  1. public static void CrearArchivoCFDI()
  2. {
  3.     try
  4.     {
  5.         string selloDigital_Certificado = "resultado";
  6.         string otro = "otro";
  7.         string Resultado = CrearSelloDigitalEmisor(ref selloDigital_Certificado, ref otro);
  8.  
  9.         using (var context = new PL_Datos.DatosBDContext())
  10.         {
  11.             PL_Datos.PLcat_Cotizacion cotizacion = (from co in context.PLcat_Cotizacion
  12.             where co.Id_PLcatCotizacion == 1
  13.             select co).Single();
  14.             foreach (PL_Datos.PLtrn_PartidasCotizacion partidas in cotizacion.PLtrn_PartidasCotizacion)
  15.             {
  16.             }
  17.            
  18.             XElement conceptos = new XElement(cfdi + "Conceptos");         
  19.            
  20.             for(int i = 0; i < 3; i++)
  21.             {
  22.                 conceptos.Add(new XElement(cfdi + "Concepto",
  23.                 new XAttribute("cantidad", ""),
  24.                 new XAttribute("unidad", ""),
  25.                 new XAttribute("noIdentificacion", ""),
  26.                 new XAttribute("descripcion", ""),
  27.                 new XAttribute("valorUnitario", ""),
  28.                 new XAttribute("importe", "")));
  29.             }          
  30.            
  31.             XNamespace cfdi = XNamespace.Get("http://www.sat.gob.mx/cfd/3");
  32.             XNamespace xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance");
  33.             XDocument xmlFactura = new XDocument(
  34.             new XDeclaration("1.0", "utf-8", "yes"),
  35.             new XComment("DATOS DE FACTURACION ELECTRONICA"),
  36.             new XElement(cfdi + "Comprobante",
  37.             new XAttribute(XNamespace.Xmlns + "cfdi", "http://www.sat.gob.mx/cfd/3"),
  38.             new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
  39.             new XAttribute(xsi + "schemaLocation", "http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd"),
  40.             new XAttribute("version", "3.2"),
  41.             new XAttribute("serie", ""),
  42.             new XAttribute("folio", "00001"),
  43.             new XAttribute("fecha", ""),
  44.             new XAttribute("sello", ""),
  45.             new XAttribute("formaDePago", ""),
  46.             new XAttribute("noCertificado", ""),
  47.             new XAttribute("certificado", ""),
  48.             new XAttribute("condicionesDePago", ""),
  49.             new XAttribute("subTotal", ""),
  50.             new XAttribute("TipoCambio", ""),
  51.             new XAttribute("Moneda", ""),
  52.             new XAttribute("total", ""),
  53.             new XAttribute("metodoDePago", ""),
  54.             new XAttribute("tipoDeComprobante", ""),
  55.             new XAttribute("LugarExpedicion", "Ciudad del Carmen, Campeche, México"),
  56.             new XElement(cfdi + "Emisor",
  57.             new XAttribute("rfc", "GAIL810405RU6"),
  58.             new XAttribute("nombre", "LAZARO GARCIA IZQUIERDO"),
  59.             new XElement(cfdi + "DomicilioFiscal",
  60.             new XAttribute("calle", "40"),
  61.             new XAttribute("noExterior", "85"),
  62.             new XAttribute("colonia", "CUAUHTEMOC CIUDAD DEL CAMREN"),
  63.             new XAttribute("municipio", "CARMEN"),
  64.             new XAttribute("estado", "CAMPECHE"),
  65.             new XAttribute("pais", "MÉXICO"),
  66.             new XAttribute("codigoPostal", "24170")),
  67.             new XElement(cfdi + "RegimenFiscal",
  68.             new XAttribute("Regimen", ""))),
  69.             new XElement(cfdi + "Receptor",
  70.             new XAttribute("rfc", ""),
  71.             new XAttribute("nombre", ""),
  72.             new XElement(cfdi + "Domicilio",
  73.             new XAttribute("pais", ""),
  74.             new XAttribute("calle", ""),
  75.             new XAttribute("estado", ""),
  76.             new XAttribute("colonia", ""),
  77.             new XAttribute("municipio", ""),
  78.             new XAttribute("noExterior", ""),
  79.             new XAttribute("noInterior", ""),
  80.             new XAttribute("codigoPostal", ""))),
  81.             conceptos,
  82.             new XElement(cfdi + "Impuestos",
  83.             new XAttribute("totalImpuestosTrasladados", ""),
  84.             new XElement(cfdi + "Traslados",
  85.             new XElement(cfdi + "Traslado",
  86.             new XAttribute("impuesto", "IVA"),
  87.             new XAttribute("tasa", ""),
  88.             new XAttribute("importe", "")))),
  89.             new XElement(cfdi + "Complemento")));
  90.  
  91.             xmlFactura.Save(@"c:\PartesEnLinea\PL_Presentacion \facturacion\prueba.xml");
  92.         }
  93.     }
  94.     catch (Exception ex)
  95.     {
  96.         throw ex;
  97.     }
  98. }

Ese bucle en un caso real sería un foreach que recorriese una lista de elementos, por ejemplo.

Por supuesto, en el ejemplo que he puesto, estás insertando 3 veces el mismo elemento, lo cual tiene poco sentido.

Hay más maneras de hacerlo, así que si puedes dar un ejemplo más claro de lo que tienes y lo que quieres, podré ampliar más la información.

Un saludo