Hi everyone, this is the first time I’ve had to use XML in n8n, and I thought the conversion to JSON would be easier. With the following workflow, I tried to do it, without success.
However, using the following site, the code transformed itself without any particular manipulation.
Hi there, I believe you are missing the Move Binary Data Node between the Set and XML. You have a String that is pretending to be an XML file, but the XML node is looking for the file, not a string. Here is an example I use for parsing WordPress XML files. The first node pulls the binary file from my files:
I’ve just tried again by adding the missing node, but unfortunately it didn’t work . The XML code will always come from an HTTP node, via an API that I’ll call. The code snippet is a simulation of the result to be obtained. Unfortunately I can’t read a file on the n8n server.
Hey @giulioandreini I have the impression that the code isn’t valid. But on the other hand, what I don’t understand is that by pasting it here in an abrupt way: https://codebeautify.org/xmltojson# it comes out correctly in JSON and the site manages to interpret it.
Hi @Jon, I let you run the workflow just below, normally I’ve taken care to integrate the XML code snippet into the Set node by copying and pasting the workflow.
Hi @arthurcorre , I’ve been playing with your sample and I’m having trouble figuring out what it could be. I’ve run your XML through 2 validators and it does seem like something is wrong with your XML output. It almost seems like it’s being truncated somehow.
It seems that the file wasn’t valid. It was missing some closing tags that I’ve framed in red on the screenshot. I also ticked the ‘Keep Source’ option in the Move Binary Data node, which solved the problem completely. I hope this helps others