NeoAjax como parsear datos recibidos en formato XML - Forum

Forum Navigation
You need to log in to create posts and topics.

NeoAjax como parsear datos recibidos en formato XML

alquie tiene idea como para ayudarme de como poder parsear los datos que recibo de una consulta en Neoajx?

El codigo que recibo es este:

<G_ServApp_Response><envioCfe><tipoComprobante>101</tipoComprobante><serie>A</serie><numero>19</numero><qrText>https://www.efactura.dgi.gub.uy/consultaQR/cfe?120249090016,101,A,19,60.00,18/06/2023,W1MD/ad88umKWLtHTnr%2bJ2WrQXg=</qrText><qrFile>/eFactura/eEmisor/lomazzi/qr/QR120249090016_101_A_19.png</qrFile><cae><id>852085</id><dNro>1</dNro><hNro>50000</hNro><fecVenc>2099-08-11</fecVenc></cae><codigoResolucion>99999/9999</codigoResolucion><codigoSeguridad>W1MD/a</codigoSeguridad><fechaFirma>20230618</fechaFirma><linkDocumento><![CDATA[http://testing.facturaexpress.com.uy:8024/FacturaExpressCliente/imprimir/imprimir.Documentos.jsp?xIdEmisor=1353755&xCodSucursal=1&xTipoComprobante=101&xSerie=A&xNumero=19&xRedirect=true]]></linkDocumento></envioCfe><codigo_retorno>00</codigo_retorno><nro_transaccion>1265242487_20230618_164302_354</nro_transaccion><mensaje_retorno>Transaccion Exitosa</mensaje_retorno></G_ServApp_Response>

 

@gustavo1973, yo intentaría convertir el XML a JSON:
https://stackoverflow.com/questions/1773550/convert-xml-to-json-and-back-using-javascript

O bien parsear directamente el XML utilizando JavaScript:
https://www.w3schools.com/xml/xml_parser.asp

Saludos!

 

@luishp entonces desde dentro de Visual no es viable darle tratamiento a esta informacion recibida por NeoAjax si es en formato XML, pregunto en base a la respuesta que me das al mandarme a sitios externos?

Pero si la informacion viene Tipo JSON si se podria? y de que manera?

@gustavo1973 claro que es posible, con cualquiera de las rutinas JavaScript que puedes encontrar en los enlaces.
Lo que no existe es un comando o plugin para realizarlo sin utilizar JavaScript, pero crear una subrutina que realice la conversión es tan sencillo como copiar y pegar.

Pero si la informacion viene Tipo JSON si se podria? y de que manera?

Como puede verse en cualquiera de los muchos ejemplos que acompañan a VisualNEO Web o si es necesario utilizando el comando ParseJSON.
Lo que si es importante es utilizar ConsoleLog para ver la estructura de los datos que se reciben ya que ahí está el truco para entender como acceder a un dato determinado.

Saludos!

@gustavo1973

Anyone has an idea to help me how to parse the data I receive from a query in Neoajx?
The code I receive is this:

I do not have experience with XML objects/formats, but your response (in a human readable format) looks like this ...

<G_ServApp_Response>

<envioCfe>

<tipoComprobante>101</tipoComprobante>
<serie>A</serie>
<numero>19</numero>
<qrText> https://www.efactura.dgi.gub.uy/consultaQR/cfe?120249090016,101,A,19,60.00,18/06/2023,W1MD/ad88umKWLtHTnr%2bJ2WrQXg=</qrText>
<qrFile>/eFactura/eEmisor/lomazzi/qr/QR120249090016_101_A_19.png</qrFile>

<cae>
<id>852085</id>
<dNro>1</dNro>
<hNro>50000</hNro>
<fecVenc>2099-08-11</fecVenc>
</cae>


<CodeResolution>99999/9999</CodeResolution>
<codeSecurity>W1MD/a</codeSecurity>
<dateSignature>20230618</dateSignature>

<linkDocument><! [CDATA[http://testing.facturaexpress.com.uy:8024/FacturaExpressCliente/imprimir/imprimir.Documentos.jsp?xIdEmisor=1353755&xCodSucursal=1&xTipoComprobante=101&xSerie=A&xNumero=19&xRedirect=true]]></linkDocument>

</envioCfe>



<codigo_retorno>00</codigo_retorno>
<nro_transaccion>1265242487_20230618_164302_354</nro_transaccion>
<mensaje_retorno>Successful Transaction</mensaje_retorno>

</ G_ServApp_Response>

As you can see, the XML format has keys that look like HTML tags, with values between them e.g.

<VoucherType>101</VoucherType>
<nro_transaccion>1265242487_20230618_164302_354</nro_transaccion>
etc.

If (and only if) you can confirm that what you receive in your subroutine is the (text) string posted in your first thread of this post (verify it by doing an AlertBox or alert or ConsoleLog on the receiving variable), provide the names of the tags whose value you seek (luckily the tag names are all unique and so the code to parse this string is straight forward).

@luishp

@gaev

Logre que me envien la respuesta en JSON  , pero si hago un ConsoleLog me dice que el JSON no es Valido

Publique la aplicacion demo en mi servidor, por si pueden verla y decirme que esta mal en el Json que recibo

https://aplicacionesuy.com/ajax

@gustavo1973

The console log also has an error 404 (i.e. not found) message.

You need to post the actual request url; unless there is some "private key" within your Application, upload the source of the Application (or at least the code associated with the Button).

@gaev

aqui esta el codigo, lo tome del original publicado por luis en su momento y lo modifique para hacer las pruebas

Uploaded files:
  • You need to login to have access to uploads.

@gustavo1973

1) It looks like you are sending the POST request to "https://aplicacionesuy.com/ajax/******" ... is this the correct URL ?

2) I used an AlertBox to see what your JSON object called [mydata] looks like ... the stringified content looks like ...

{"urlSoap":"http://******","Issuerid":"1353755","BranchCode":1,"VoucherType":101,"Series":"A","Number":"?","IssueDate":"20230620","PaymentForm":1,"user":"interface","password":"xxx","xmlData":"1 3 UY Jump 13Claldy Milk 1L1N/A 48 48.00 0.00 0.00 0.00 0.00 UYU1 0.00 0.00 0.00 39.341022 0.00 8.66 48 0.0048"}

Note: I have xxx'ed out the password key.

Are all other key/value pairs correctly composed ? ... perhaps the server is responding with a message that says there is no matching data to return.

I am sorry I can not help you with this version of your attempt as there are too many unknowns (to me) ... BTW, have you abandoned your initial efforts to parse the xml format data received (as posted in your first thread) ?

@gaev

If I go back to the beginning of the post, and receive the data in XML, how do I get the following values:

tipoComprobante
serie
numero
qrFile
linkDocumento
codigo_retorno

These would be the data that I need to extract from the response received in xml




@gustavo1973

Upload the App where you received the data string that you posted in the first thread of this post.

 If the receiving variable contains a string (like the one you posted), I will add the code to parse it in order to extract the requested values.

Realize that I can not test it for you as it appears that it needs to be compiled and uploaded to a server (in order to get around the CORS limitations).

 

@gaev

The application is already compiled on the server and I receive the xml file in the subroutine
I also attached the project

https://aplicacionesuy.com/ajax
Uploaded files:
  • You need to login to have access to uploads.

@gustavo1973

When I clicked on the link "https://aplicacionesuy.com/ajax" , I got a blank screen

After I presse dF12, the console tabs says ...

DevTools failed to load source map: Could not load content for https://aplicacionesuy.com/ajax/css/bootstrap.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

In my previous post I asked ...

1) It looks like you are sending the POST request to "https://aplicacionesuy.com/ajax/******" ... is this the correct URL ?

You did not answer this question; I note that in your App in the latest post, you are sending the query to "https://aplicacionesuy.com/Dumbo/SoapNeo.php"; can you please explain the discrepancy?

In your subroutine that receives  [data] (i.e. parseData2), ASSUMING that it receives the xml data as a string, add this code ...

StrParse "[data]" "<tipoComprobante>" "[arrayA]"

... now [arrayA(0)] will contain <G_ServApp_Response><envioCfe>
... and [arrayA(1)] will contain 101</tipoComprobante><serie>A</serie> etc. etc.

SetVar "[textA]" "[arrayA(1)]"
StrParse "[textA]" "</tipoComprobante>" "[arrayB]"
... now [arrayB(0)]" will contain 101
... and [arrayB(1) will contain everything else

... validate that you are extracting the correct value
AlertBox "from subroutine" "[arrayB(0)]" ""

Please note that the Forum software automatically changes tag names in the code above to their ENGLISH Translation (you will need to revert to your original tags, as I can not make it NOT translate).

If this works, then you can extract the other values with similar code (just replace [arrayA], [textA] and [arrayB] with different names (like [arrayC], [textC] and [arrayD], and so on for each item you want to extract.

 

@gaev

In the first post of the project, avoid putting the real web address for a security issue, 
in the second post of the project it was already with the real address
neoajak communicates with a php on my server that is the one who communicates with the api that returns the data

You did not answer this question; I note that in your App in the latest post, you are sending the query to "https://aplicacionesuy.com/Dumbo/SoapNeo.php"; can you please explain the discrepancy?
It is my mistake, the correct address to which NeoAjax points is the following: it has already been corrected in the server app
neoAjaxSend "https://aplicacionesuy.com/ajax/SoapNeo.php" "POST" "[mydata]" "text" "parseData2" "error"

In your subroutine that receives  [data] (i.e. parseData2), ASSUMING that it receives the xml data as a string, add this code ...

Yes,
Enter the code and the result I get in the browser console is "Cannot read properties of undefined (reading '0')"

You can test the message that the console gives in the online application
Another thing, if you can test the project locally, you just have to change the address in neoajax :
neoAjaxSend "http://localhost/SoapNeo.php" "POST" "[mydata]" "text" "parseData2" "error"
I can send you by private mail if you want the php file to test locally there
My email is: gustavo.lomazzi.1973@gmail.com

@gustavo1973

I am sorry but I can not get into debugging your application.

When I first tried to assist, it was a simple case of extracting values for specified keys in a supposed string data. It looks like the data you posted is NOT a string.

With all the complications of compiling the App and running it from a server location, it becomes too much; you may have to pay someone with the time, the expertise in XML etc. to do what you seek.

@gaev

Thank you very much for your help and your time