I am making an application that is responsible for separating XML files based on some parameters, so far so good, but now with the CFDI changes my programming has crashed, since users can have the cfdi 3.2 and 3.3 documents mixed in the same folder .
What makes me go through the documents is that in version 3.2 I obtained the data in this way:
strVersion = doc.GetElementsByTagName("cfdi:Comprobante")(0).Attributes("version").Value
but now with the change to 3.3 it fails me since they changed the first letter of the attributes to uppercase, and now it would be
strVersion = doc.GetElementsByTagName("cfdi:Comprobante")(0).Attributes("Version").Value
there will be a way that in case the attribute ("version")
does not exist then it takes the value ("Version")
, or that Attributes
it does not distinguish between version
and Version
, I hope I make myself understood and you can suggest me something.
I attach the structure of the XML to see if its values can be retrieved in a different way than what I do.
Version 3.3
<?xml version="1.0" encoding="UTF-8"?>
<cfdi:Comprobante Certificado="MIQ=" Fecha="2018-02-01T01:56:11" Folio="012180001054132653" FormaPago="03" LugarExpedicion="06600" TipoCambio="1" TipoDeComprobante="I" Total="0000.00" Version="3.3" xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd">
<cfdi:Emisor Nombre="BBVA BANCOMER, S A" RegimenFiscal="w232" Rfc="RFSGEGHSFS"/>
<cfdi:Receptor Nombre="XXXXXXXXXXXXX" Rfc="XXXXXXXXXXXXXXXXXX" UsoCFDI="XXX"/>
</cfdi:Comprobante>
Version 3.2
<?xml version="1.0" encoding="UTF-8"?>
<cfdi:Comprobante xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd http://www.sat.gob.mx/ine http://www.sat.gob.mx/sitio_internet/cfd/ine/ine11.xsd" version="3.2" serie="TF" sello="J=" noCertificado="00001000000402403936" certificado="MI=" condicionesDePago="PAGO INMEDIATO SIN DESC. POR P" subTotal="0.00" TipoCambio="1.00000" Moneda="MXN" total="0.00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cfdi="http://www.sat.gob.mx/cfd/3">
<cfdi:Emisor rfc="RFCGF242FD" nombre="Lorem">
</cfdi:Emisor>
<cfdi:Receptor rfc="EWCVFFSFDF" nombre="Lorem imp">
</cfdi:Receptor>
</cfdi:Comprobante>
For XML in .NET I recommend that you use the XDocument class and its related ones.
UPDATE:
Hello, to obtain nodes it is with XElement, following the previous example it would be:
That is, Root is the root or first node, from there with XElement you access the following nodes using the namespace to which it belongs. The node attributes for this CFDI case do not require a namespace, you only indicate the name.