Search code examples
node.jsxmlencodingutf-8xml2js

How to convert XML enconding in Node


I'm trying to parse XML file in Node with xml2js library.

The issue is that the file encoding is windows-1250 instead of utf-8.

So when I try to get the values it contains wrong characters. For example, instead of ř I get Ĺ™.

How can I convert the xml file or the string values to utf-8 in Node?


Solution

  • You can try util.TextDecoder, but you will need full ICU for this (see details how to check or get it).

    Alternatively, you can try npm modules like iconv-lite.