Ver Mensaje Individual
  #3 (permalink)  
Antiguo 20/01/2015, 00:53
wwwmaster
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Respuesta: leer xml a datatable

Yo leo los xml's de facturas electronicas asi:

ASegurate que tu XML este grabado como UTF-8, esto lo puedes verificar abriendo el .xml con notepad y darle "guardar como" y hasta abajo en un combo box de formato debe decir "UTF-8" (independientemente de la etiqueta UTF-8 que esta contenida en el texto)



Dim doc As New System.Xml.XmlDocument
Try
doc.Load(nombreArchivoDestino)
'//Obtenemos el nodo raiz del documento.
Dim comprobante As XmlElement = doc.DocumentElement

' Oct 2013
' Revisamos si es un CFD o un CFDI
Dim tipoDeCFD As String = ""
Dim prefijo As String = ""
If comprobante.Attributes.GetNamedItem("version").Val ue() = "3.2" Then
tipoDeCFD = "CFDI"
prefijo = "cfdi:"
End If
If comprobante.Attributes.GetNamedItem("version").Val ue() = "2.2" Then
tipoDeCFD = "CFD"
End If
If comprobante.Attributes.GetNamedItem("version").Val ue() = "2.0" Then
tipoDeCFD = "CFD"
End If


'Dim fechaCFDI As String = comprobante.Attributes.GetNamedItem("fecha").Value ()
' Convertimos la fecha al formato que pide el campo
' La fecha NO SE TOMARA EN CUENTA, se agrega con fecha actual
'If fechaCFDI <> "" Then '2014-11-06T17:24:36
' fechaCFDI = fechaCFDI.Substring(0, 10)
' Dim arrTMPFechaCFDI As String() = fechaCFDI.Split("-")
' If arrTMPFechaCFDI.Length > 2 Then
' fechaCFDI = arrTMPFechaCFDI(2) & "/" & arrTMPFechaCFDI(1) & "/" & arrTMPFechaCFDI(0) ' dd/mm/aaaa
' txtFecha.Text = fechaCFDI
' txtFecha.BackColor = Drawing.Color.Yellow
' End If
'End If
'------------------------------------------------
' Recuperamos datos de emisor y los conceptos
'------------------------------------------------

Dim nodoEmisor As XmlNode = comprobante.Item("cfdi:Emisor")

'nodoTimbre = nodoEmisor.Item("tfd:TimbreFiscalDigital")
Dim emisorNombre As String = nodoEmisor.Attributes.GetNamedItem("nombre").Value ()
If emisorNombre <> "" Then
txtNombre.Text = emisorNombre
txtNombre.BackColor = Drawing.Color.Yellow
End If