XML - Como coloco el prefijo cfdi en cada uno de los nombres de nodos del XML

 
Vista:
sin imagen de perfil

Como coloco el prefijo cfdi en cada uno de los nombres de nodos del XML

Publicado por Halcón Divino (3 intervenciones) el 05/05/2011 17:24:04
Que tal colegas :

Mi pregunta es ¿¿¿ Como coloco el prefijo cfdi en cada uno de los nombres de nodos del XML ??? de tal forma que quede de la siguiente manera:
<cfdi:DomicilioFiscal ……

Les anexo parte del código en C# que desarrollé para generar el XML del CFD I
Lo unció que me falta es poner el prefijo cfdi a cada uno de los nodos

Me podrían explicar como realizarlo.

Gracias
Saludos

Halcón Divino
Monterrey, Nuevo León, México


#region Genera el XML
string ArchivoXML = dsDatos.Tables[0].Rows[0]["eRFC"].ToString().Trim() + "_" + dsDatos.Tables[0].Rows[0]["SerieReferente"].ToString().Trim() + "_" + dsDatos.Tables[0].Rows[0]["FolioReferente"].ToString().Trim() + ".XML";
XmlDeclaration CCDeclaracionXML;
XmlNode nCFDI;
XmlNode nEmisor;
XmlNode neDomicilio;
XmlNode nExpedido;
XmlNode nReceptor;
XmlNode nrDomicilio;
XmlNode nConceptos;
XmlNode nConcepto;
XmlNode nImpuestos;
XmlNode nRetenciones;
XmlNode nRetencion;
XmlNode nTrasladados;
XmlNode nTrasladado;

XmlDocument CCXml = new XmlDocument();
CCDeclaracionXML = CCXml.CreateXmlDeclaration("1.0", "UTF-8", "");

//Add the new node to the document.
XmlElement root = CCXml.DocumentElement;
CCXml.InsertBefore(CCDeclaracionXML, root);


XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("cfdi", "www.sat.gob.mx/cfd/3");
// XmlSerializer serializer = new XmlSerializer( ( (cfdi.GetType(), "www.sat.gob.mx/cfd/3");

// serializer.Serialize(writer, cfdi, ns);

#region Se define el nodo Comprobante
nCFDI = CCXml.CreateNode(XmlNodeType.Element, "Comprobante", "");

//Se le Agrega atributos al nodo Comprobante
AgregaAtributo("S", "C",ref CCXml, ref nCFDI, "xsi:schemaLocation","http://www.sat.gob.mx/cfd/3 cfdv3.xsd", "");
AgregaAtributo("S", "C",ref CCXml, ref nCFDI, "xmlns:cfdi" , "http://www.sat.gob.mx/cfd/3", "");
AgregaAtributo("S", "C",ref CCXml, ref nCFDI, "xmlns:xsi" , "http://www.w3.org/2001/XMLSchema-instance", "");
AgregaAtributo("S", "N",ref CCXml, ref nCFDI, "version" , "3.0", "");
AgregaAtributo("N", "C",ref CCXml, ref nCFDI, "serie" , dsDatos.Tables[0].Rows[0]["SerieReferente"].ToString(), "");
AgregaAtributo("N", "N",ref CCXml, ref nCFDI, "folio" , dsDatos.Tables[0].Rows[0]["FolioReferente"].ToString(), "");
AgregaAtributo("S", "D",ref CCXml, ref nCFDI, "fecha" , FormatYYYYMMDDTHHMMSS(dsDatos.Tables[0].Rows[0]["FechaHora"].ToString()), "");
AgregaAtributo("S", "C",ref CCXml, ref nCFDI, "formaDePago" , dsDatos.Tables[0].Rows[0]["FormaDePago"].ToString(), "");
AgregaAtributo("N", "C",ref CCXml, ref nCFDI, "condicionesDePago", dsDatos.Tables[0].Rows[0]["CondicionesDePago"].ToString(), "");
AgregaAtributo("S", "$",ref CCXml, ref nCFDI, "subTotal" , dsDatos.Tables[0].Rows[0]["Importe"].ToString(), "");
AgregaAtributo("N", "$",ref CCXml, ref nCFDI, "descuento" , dsDatos.Tables[0].Rows[0]["Descuento"].ToString(), "");
AgregaAtributo("N", "C",ref CCXml, ref nCFDI, "motivoDescuento" , dsDatos.Tables[0].Rows[0]["MotivoDescuento"].ToString(), "");
AgregaAtributo("N", "$",ref CCXml, ref nCFDI, "TipoCambio" , dsDatos.Tables[0].Rows[0]["Paridad"].ToString(), "");
AgregaAtributo("N", "C",ref CCXml, ref nCFDI, "Moneda" , dsDatos.Tables[0].Rows[0]["Moneda"].ToString(), "");
AgregaAtributo("S", "$",ref CCXml, ref nCFDI, "total" , dsDatos.Tables[0].Rows[0]["Total"].ToString(), "");
AgregaAtributo("N", "C",ref CCXml, ref nCFDI, "metodoDePago" , dsDatos.Tables[0].Rows[0]["MetodoDePago"].ToString(), "");
AgregaAtributo("S", "C",ref CCXml, ref nCFDI, "tipoDeComprobante", dsDatos.Tables[0].Rows[0]["TipoCFD"].ToString(), "");
AgregaAtributo("S", "C",ref CCXml, ref nCFDI, "sello" , SelloDigital, "");
AgregaAtributo("S", "N",ref CCXml, ref nCFDI, "noCertificado" , noCertificado, "");
AgregaAtributo("S", "C",ref CCXml, ref nCFDI, "certificado" , Certificado, "");

#region Se agrega el nodo EMISOR al nodo nCFDI
nEmisor = CCXml.CreateNode(XmlNodeType.Element, "Emisor", "");

AgregaAtributo("S","C",ref CCXml, ref nEmisor, "rfc" , dsDatos.Tables[0].Rows[0]["eRFC"].ToString(), "");
AgregaAtributo("S","C",ref CCXml, ref nEmisor, "nombre", dsDatos.Tables[0].Rows[0]["eNombre"].ToString(), "");

neDomicilio = CCXml.CreateNode(XmlNodeType.Element, "DomicilioFiscal", "");

AgregaAtributo("S","C",ref CCXml, ref neDomicilio, "calle" , dsDatos.Tables[0].Rows[0]["eDireccion"].ToString(), "");
AgregaAtributo("N","N",ref CCXml, ref neDomicilio, "noExterior" , dsDatos.Tables[0].Rows[0]["eNumero"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref neDomicilio, "noInterior" , dsDatos.Tables[0].Rows[0]["eInterior"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref neDomicilio, "colonia" , dsDatos.Tables[0].Rows[0]["eColonia"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref neDomicilio, "localidad" , dsDatos.Tables[0].Rows[0]["eLocalidad"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref neDomicilio, "referencia" , dsDatos.Tables[0].Rows[0]["eReferencia"].ToString(), "");
AgregaAtributo("S","C",ref CCXml, ref neDomicilio, "municipio" , dsDatos.Tables[0].Rows[0]["eMunicipio"].ToString(), "");
AgregaAtributo("S","C",ref CCXml, ref neDomicilio, "estado" , dsDatos.Tables[0].Rows[0]["eEstado"].ToString(), "");
AgregaAtributo("S","C",ref CCXml, ref neDomicilio, "pais" , dsDatos.Tables[0].Rows[0]["ePais"].ToString(), "");
AgregaAtributo("S","N",ref CCXml, ref neDomicilio, "codigoPostal", dsDatos.Tables[0].Rows[0]["eCP"].ToString(), "");

nEmisor.AppendChild(neDomicilio);

nExpedido = CCXml.CreateNode(XmlNodeType.Element, "ExpedidoEn", "");

AgregaAtributo("N","C",ref CCXml, ref nExpedido, "calle" , dsDatos.Tables[0].Rows[0]["xDireccion"].ToString(), "");
AgregaAtributo("N","N",ref CCXml, ref nExpedido, "noExterior" , dsDatos.Tables[0].Rows[0]["xNumero"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nExpedido, "noInterior" , dsDatos.Tables[0].Rows[0]["xInterior"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nExpedido, "colonia" , dsDatos.Tables[0].Rows[0]["xColonia"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nExpedido, "localidad" , dsDatos.Tables[0].Rows[0]["xLocalidad"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nExpedido, "municipio" , dsDatos.Tables[0].Rows[0]["xMunicipio"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nExpedido, "estado" , dsDatos.Tables[0].Rows[0]["xEstado"].ToString(), "");
AgregaAtributo("S","C",ref CCXml, ref nExpedido, "pais" , dsDatos.Tables[0].Rows[0]["xPais"].ToString(), "");
AgregaAtributo("N","N",ref CCXml, ref nExpedido, "codigoPostal", dsDatos.Tables[0].Rows[0]["xCP"].ToString(), "");

nEmisor.AppendChild(nExpedido);

nCFDI.AppendChild(nEmisor);
#endregion

#region Se agrega el nodo RECEPTOR al nodo nCFDI
nReceptor = CCXml.CreateNode(XmlNodeType.Element, "Receptor", "");

AgregaAtributo("S", "C", ref CCXml, ref nReceptor, "rfc", dsDatos.Tables[0].Rows[0]["rRFC"].ToString(), "www.sat.gob.mx/cfd/3");
AgregaAtributo("N","C",ref CCXml, ref nReceptor, "nombre", dsDatos.Tables[0].Rows[0]["rNombre"].ToString(), "");

nrDomicilio = CCXml.CreateNode(XmlNodeType.Element, "Domicilio", "");

AgregaAtributo("N","C",ref CCXml, ref nrDomicilio, "calle" , dsDatos.Tables[0].Rows[0]["rDireccion"].ToString(), "");
AgregaAtributo("N","N",ref CCXml, ref nrDomicilio, "noExterior" , dsDatos.Tables[0].Rows[0]["rNumero"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nrDomicilio, "noInterior" , dsDatos.Tables[0].Rows[0]["rInterior"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nrDomicilio, "colonia" , dsDatos.Tables[0].Rows[0]["rColonia"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nrDomicilio, "localidad" , dsDatos.Tables[0].Rows[0]["rLocalidad"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nrDomicilio, "referencia" , dsDatos.Tables[0].Rows[0]["rReferencia"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nrDomicilio, "municipio" , dsDatos.Tables[0].Rows[0]["rMunicipio"].ToString(), "");
AgregaAtributo("N","C",ref CCXml, ref nrDomicilio, "estado" , dsDatos.Tables[0].Rows[0]["rEstado"].ToString(), "");
AgregaAtributo("S","C",ref CCXml, ref nrDomicilio, "pais" , dsDatos.Tables[0].Rows[0]["rPais"].ToString(), "");
AgregaAtributo("N","N",ref CCXml, ref nrDomicilio, "codigoPostal", dsDatos.Tables[0].Rows[0]["rCP"].ToString(), "");

nReceptor.AppendChild(nrDomicilio);

nCFDI.AppendChild(nReceptor);
#endregion

#region Se agrega el nodo CONCEPTOS al nodo nCFDI
nConceptos = CCXml.CreateNode(XmlNodeType.Element, "Conceptos", "");

if (Origen == "FACTURA")
{
for (i = 0; i <= dsItems.Tables[0].Rows.Count - 1; i++)
{

//Se agrega el nodo CONCEPTO al nodo CONCEPTOS
nConcepto = CCXml.CreateNode(XmlNodeType.Element, "Concepto", "");

PU = string.Format("{0:0.00}", Convert.ToDouble(dsItems.Tables[0].Rows[i]["importe"].ToString()) / Convert.ToDouble(dsItems.Tables[0].Rows[i]["Cantidad"].ToString()));

AgregaAtributo("S", "N", ref CCXml, ref nConcepto, "cantidad", dsItems.Tables[0].Rows[i]["Cantidad"].ToString(), "");
AgregaAtributo("N", "C", ref CCXml, ref nConcepto, "unidad", dsItems.Tables[0].Rows[i]["Unidad"].ToString(), "");
AgregaAtributo("N", "C", ref CCXml, ref nConcepto, "noIdentificacion", dsItems.Tables[0].Rows[i]["Clave"].ToString(), "");
AgregaAtributo("S", "C", ref CCXml, ref nConcepto, "descripcion", dsItems.Tables[0].Rows[i]["Descripcion"].ToString(), "");
AgregaAtributo("S", "$", ref CCXml, ref nConcepto, "valorUnitario", PU, "");
AgregaAtributo("S", "$", ref CCXml, ref nConcepto, "importe", dsItems.Tables[0].Rows[i]["importe"].ToString(), "");

nConceptos.AppendChild(nConcepto);
}
}
else
{
//Se agrega el nodo CONCEPTO al nodo CONCEPTOS
nConcepto = CCXml.CreateNode(XmlNodeType.Element, "Concepto", "");

AgregaAtributo("S", "N", ref CCXml, ref nConcepto, "cantidad" , "1", "");
AgregaAtributo("N", "C", ref CCXml, ref nConcepto, "unidad" , "", "");
AgregaAtributo("N", "C", ref CCXml, ref nConcepto, "noIdentificacion", "", "");
AgregaAtributo("S", "C", ref CCXml, ref nConcepto, "descripcion" , dsDatos.Tables[0].Rows[0]["Concepto"].ToString(), "");
AgregaAtributo("S", "$", ref CCXml, ref nConcepto, "valorUnitario" , dsDatos.Tables[0].Rows[0]["Importe"].ToString(), "");
AgregaAtributo("S", "$", ref CCXml, ref nConcepto, "importe" , dsDatos.Tables[0].Rows[0]["Importe"].ToString(), "");

nConceptos.AppendChild(nConcepto);

}


nCFDI.AppendChild(nConceptos);
#endregion

#region Se agrega el nodo IMPUESTOS al nodo nCFDI
nImpuestos = CCXml.CreateNode(XmlNodeType.Element, "Impuestos", "");

if (false)
{
//Se agrega el nodo Retencion al nodo Impuestos
nRetenciones = CCXml.CreateNode(XmlNodeType.Element, "Retenciones", "");

//Se agrega el nodo Retencion al nodo Retenciones
nRetencion = CCXml.CreateNode(XmlNodeType.Element, "Retencion", "");
AgregaAtributo("S", "C", ref CCXml, ref nRetencion, "impuesto", dsDatos.Tables[0].Rows[0]["tLeyendaISR"].ToString(), "");
AgregaAtributo("S", "$", ref CCXml, ref nRetencion, "importe", dsDatos.Tables[0].Rows[0]["tImporteISR"].ToString(), "");
nRetenciones.AppendChild(nRetencion);

//Se agrega el nodo Retencion al nodo Retenciones
nRetencion = CCXml.CreateNode(XmlNodeType.Element, "Retencion", "");
AgregaAtributo("S", "C", ref CCXml, ref nRetencion, "impuesto", dsDatos.Tables[0].Rows[0]["tLeyendaIVA"].ToString(), "");
AgregaAtributo("S", "$", ref CCXml, ref nRetencion, "importe", dsDatos.Tables[0].Rows[0]["tImporteIVA"].ToString(), "");
nRetenciones.AppendChild(nRetencion);

nImpuestos.AppendChild(nRetenciones);
}

//Se agrega el nodo Trasladados al nodo Impuesto
nTrasladados = CCXml.CreateNode(XmlNodeType.Element, "Traslados", "");

//Se agrega el nodo Retencion al nodo Retenciones
nTrasladado = CCXml.CreateNode(XmlNodeType.Element, "Traslado", "");
AgregaAtributo("S", "C", ref CCXml, ref nTrasladado, "impuesto" , dsDatos.Tables[0].Rows[0]["rLeyendaIVA"].ToString(), "");
AgregaAtributo("S", "$",ref CCXml, ref nTrasladado, "tasa" , dsDatos.Tables[0].Rows[0]["rTasaIVA"].ToString(), "");
AgregaAtributo("S", "$",ref CCXml, ref nTrasladado, "importe" , dsDatos.Tables[0].Rows[0]["rImpuestoIVA"].ToString(), "");
nTrasladados.AppendChild(nTrasladado);

nImpuestos.AppendChild(nTrasladados);


nCFDI.AppendChild(nImpuestos);
#endregion

//Se le Agrega al nodo Comprobante al XML
CCXml.AppendChild(nCFDI);
#endregion

CCXml.Save(RutaXML + ArchivoXML);
#endregion XML
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder