How to parse XML from URL – problem with encoding

Hello, I have a workflow where I use an HTTP request to download data from XML that is stored online.

I get the data as a string but when I try to convert it to JSON (XML to JSON module), I am getting this error:

ERROR: Non-whitespace before first tag. Line: 0 Column: 1 Char: �

I assume the problem is with encoding. Here are my two questions:

  1. How can I find out what is the original encoding?
  2. How can I change the encoding of the string?
  3. Is there any different way how can I solve this problem?

I would share the workflow but the XML URL address is confidential. Please let me know if can provide you with some further information.

Thank you.

Welcome to the community @honzapav!

That sounds like it is maybe BOM related. You can check out this post:

There it says that you can try to fix it with: origString.replace("\ufeff", "")

If you need additional guidance simply get back to us.

1 Like

Hi @jan, thanks for the help. Finally, it was easier to get the xml in utf-8 (originally it was utf-16 as I found out). After this change, finishing my first n8n workflow was a piece of cake :wink:.

1 Like

That is great to hear. Have fun!

I wonder if I can get some help for this error? Putting a function node to run .replace() returns an error that replace is not a function. I am struggling to understand how n8n works.

To be able to help please share the code you have in the Function-Node. You can also find the documentation here: Function - n8n Documentation
which will also probably help you to figure out what is going wrong.

Generally does a Function-Node have to return an array of objects.

If you get the message the replace is not a function, I assume that whatever variable you try to run replace on, is not actually a string.