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!