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
{
  "name": "json_to_xml_to_file",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        350
      ]
    },
    {
      "parameters": {
        "url": "https://demo.papercut.com/api/health/printers",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "adtNetfm7bnlNTNzEe2iTTuxyuIOvkN7"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        430,
        350
      ]
    },
    {
      "parameters": {
        "mode": "jsonToxml",
        "options": {}
      },
      "name": "XML",
      "type": "n8n-nodes-base.xml",
      "typeVersion": 1,
      "position": [
        630,
        350
      ]
    },
    {
      "parameters": {
        "command": "=cat >/home/node/.n8n/printer-status.xml <<EOL\n{{$json[\"data\"]}}\nEOL"
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        840,
        350
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "XML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "XML": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 30
}

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