0

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.

Yakir
  • 1
  • 2
  • *The example of how to **read** and write* - have you actually read that XML back? That's a numerical character reference to a Hebrew letter, https://en.wikipedia.org/wiki/Aleph#Character_encodings `5D0` is the number itself, and the `&...;` part makes it recognizable to the reader. – tevemadar Mar 17 '22 at 09:26
  • Does this answer your question? [Ways to represent UTF-8 in XML messages](https://stackoverflow.com/questions/43729953/ways-to-represent-utf-8-in-xml-messages) – tevemadar Mar 17 '22 at 09:26

0 Answers0