XML to Binary

I believe my question might be a little silly, but I’m getting a lot of hits. I created a stream that does an http authentication and downloads a json, I need to convert this json into an xml and expose it, but I couldn’t find a way to create the XML binary. Can you guide me how to do or how to start?

[image]

Hey @lucascosta,

Have you checked out the XML node? It can convert data to and from XML and sounds like it is what you are looking for.

Yes @Jon , I read this part, but I need to generate an .xml file, I’m stuck in this part, to be honest, I don’t know how to proceed to generate it.

Alright I have had a quick play and I have a solution to go from JSON > XML > Local File I have done it using a public demo site so if anyone happens to use PaperCut it also shows you how you can use their Health Monitoring API with n8n :wink:

The workflow itself looks like this:

So we do the HTTP Request which returns JSON then use the XML node to convert that to XML then because the Binary swap node and write to file doesn’t play ball and I am not sure how to set a new Binary Object in a function I have used Execute Command to output the data.

Workflow Example

Hopefully this helps and covers what you need :+1:

2 Likes

Hi Jon, thanks so much for the help, it worked perfectly. It took me a while to answer because the api I’m consuming was down, but I managed to test it and everything worked out.

1 Like

I’m tryng to do the inverse of this.
I have an XML file and I want to convert it to JSON, but N8N says XML: No json property “data” does not exists on item!"

Any ideas? I have tried many different names for the property Name but just doesn’t work.

I can’t upload files, so I’m pasting the content of the XML I’m using here, just copy and paste it on a file called 1.xml and put where N8N can get it.

<?xml version="1.0" encoding="UTF-8"?><MensajeHacienda xmlns="https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/mensajeHacienda">
    <Clave>50607022200310111982936700367010000413605177667299</Clave>
    <NombreEmisor>Aerocasillas S.A</NombreEmisor>
    <TipoIdentificacionEmisor>02</TipoIdentificacionEmisor>
    <NumeroCedulaEmisor>3101119829</NumeroCedulaEmisor>
    <NombreReceptor>Gabriel Paniagua Castro</NombreReceptor>
    <TipoIdentificacionReceptor>01</TipoIdentificacionReceptor>
    <NumeroCedulaReceptor>114210047</NumeroCedulaReceptor>
    <Mensaje>1</Mensaje>
    <DetalleMensaje> </DetalleMensaje>
    <MontoTotalImpuesto>0.00000</MontoTotalImpuesto>
    <TotalFactura>17.06000</TotalFactura>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="id-a87d1339cb3663820c29bb64eddac40a"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><ds:Reference Id="r-id-1" Type="" URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116"><ds:XPath>not(ancestor-or-self::ds:Signature)</ds:XPath></ds:Transform><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>gIBbSXOVJsoaI2bvM9UAlO/kEZfS1Lp5cFTBYjvbPcE=</ds:DigestValue></ds:Reference><ds:Reference Type="http://uri.etsi.org/01903#SignedProperties" URI="#xades-id-a87d1339cb3663820c29bb64eddac40a"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>yyHQfAKJfCZr0nNwqbGT2IINWz8c5sEKe5vhJ+bfEgE=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue Id="value-id-a87d1339cb3663820c29bb64eddac40a">MY2f71XGEp/X/T+VFfePRj4tCi36E9UJezf79tCUYv62AQBJZXU4xgeMMSRVwUzWT3pfs+2KIajZQijT9UiA/p2j8yGZVPZecUic4T+8DWS18YzYlvlgzXqvHZxVtlrDrkPfxHNoFUXtYWJbWo5gVcEsY24EzizviqXlKM+RwJ/59OK7WloMHWj/QNc6ESmx9EnFMDnGAt5Kwa2o++h0yvEgNCBGzYLBL06Zt7MdfoamhFmLwzxga3eGdpA3BWDoMd+DJ7KTilZNgvzUC6CJIutOgNIFU0hL05bqLAfNidh3ta8W0x0p6fdsZ1IWxxDe9pdsEMUzjrTxVS/lzZsFxg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6Ly9mZGkuc2lucGUuZmkuY3IvcmVwb3NpdG9yaW8vQ0ElMjBTSU5QRSUyMC0lMjBQRVJTT05BJTIwSlVSSURJQ0ElMjB2MigxKS5jcmwwgZoGCCsGAQUFBwEBBIGNMIGKMCgGCCsGAQUFBzABhhxodHRwOi8vb2NzcC5zaW5wZS5maS5jci9vY3NwMF4GCCsGAQUFBzAChlJodHRwOi8vZmRpLnNpbnBlLmZpLmNyL3JlcG9zaXRvcmlvL0NBJTIwU0lOUEUlMjAtJTIwUEVSU09OQSUyMEpVUklESUNBJTIwdjIoMSkuY3J0MDwGCSsGAQQBgjcVBwQvMC0GJSsGAQQBgjcVCIXE6luC0eM1lZEbgvmXGIaly2uBf4GQhnXeslwCAWQCAQkwEwYDVR0lBAwwCgYIKwYBBQUHAwQwGwYJKwYBBAGCNxUKBA4wDDAKBggrBgEFBQcDBDAVBgNVHSAEDjAMMAoGCGCBPAEBAQEGMA0GCSqGSIb3DQEBCwUAA4IBAQAjwqs2HCx9VqLCHhh3EtFvZpjx9DCxeclmol5g6S+mDrQJ2IP+l2GvbnDOzLkWZ3q4kLmF+O8hhWxCF3hQ4rjHh3syxNjsVzbTuZyu/hEfxb9VzN7vgrL/HW9D/rOGsqvCBhqU3wJAaribkm6qcQoB40+Ucl4tVbhUZ0b0z0bwaGEmFsWSkmTzc0RgiG5eDJ3h63Dknl3GtvKi6miHQhmHQrFjzw8DdxLa124OZiNVuosAKD1sRnkr+qxvv12oQhvvHSbNQUfMX8FRAtDUK3zTe6iBAXjDeUwdR0NBO+7pmcBQycKJOIELeQhHcMyJN/GFIeqeY15pzPc44LLi1yQ6</ds:X509Certificate></ds:X509Data></ds:KeyInfo><ds:Object><xades:QualifyingProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" Target="#id-a87d1339cb3663820c29bb64eddac40a"><xades:SignedProperties Id="xades-id-a87d1339cb3663820c29bb64eddac40a"><xades:SignedSignatureProperties><xades:SigningTime>2022-02-07T22:00:45Z</xades:SigningTime><xades:SigningCertificate><xades:Cert><xades:CertDigest><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>HJIgRkgbPn6paA0PP2d5Fb0+ULQ=</ds:DigestValue></xades:CertDigest><xades:IssuerSerial><ds:X509IssuerName>CN=CA SINPE - PERSONA JURIDICA v2,OU=DIVISION SISTEMAS DE PAGO,O=BANCO CENTRAL DE COSTA RICA,C=CR,2.5.4.5=#131043504a2d342d3030302d303034303137</ds:X509IssuerName><ds:X509SerialNumber>1605653657074860149031926172554884987230355991</ds:X509SerialNumber></xades:IssuerSerial></xades:Cert></xades:SigningCertificate></xades:SignedSignatureProperties><xades:SignedDataObjectProperties><xades:DataObjectFormat ObjectReference="#r-id-1"><xades:MimeType>application/octet-stream</xades:MimeType></xades:DataObjectFormat></xades:SignedDataObjectProperties></xades:SignedProperties></xades:QualifyingProperties></ds:Object></ds:Signature></MensajeHacienda>

Hola Gabriel, yo ocupe el nodo “Move Binary Data” para leer el XML.

Salu2

Lo intenté también pero no funcionó.
Lo que logré fue encontrar una función de javascript para convertir Base64 a XML y con eso logré ver el XML, luego usé el módulo de XML a JSON y listo. Funcionó bien!

Si puedes poner tu ejemplo, para ver cómo lo lograrias con un binario a XML