How to write to xml file with hebrew content

188 views Asked by At

I have an XML file with number of Records with Hebrew content and after I read It I want to save some of the Records that satisfied special condition to new XML file, but when I wrote to this new file, the Hebrew content convert to Gibberish like this:

<record>
...
  <datafield tag="100" ind1=" " ind2=" ">
    <subfield code="a">&#x5D0;&#x5D1;&#x5D3;&#x5D9;, &#x5D0;&#x5D4;&#x5E8;&#x5DF; &#x5D1;&#x5DF; &#x5E6;&#x5D1;&#x5D9;</subfield>
    <subfield code="9">heb</subfield>
  </datafield>
...
</record>

Here is part of my code:

let writers = ['marcxml', 'iso2709', 'json', 'text'].map(type => Marc.stream(fs.createWriteStream('results\\Short Stories.' + type), type));
...
writers.forEach((writer) => writer.write(record));
...
writers.forEach(writer => writer.end());

The example of how to read and write from XML file with Marc21 encoding is taken from here: https://www.npmjs.com/package/marcjs

Note: I tried to add "utf-8" encoding but it didn't work.

0

There are 0 answers