I'm using a class to convert xml to json for my project like so:
export class AccessionClass {
constructor(accessionFilename) {
this.accessionFilename = accessionFilename
this.accessionXML = fs.readFileSync(this.accessionFilename).toString()
const parser = new xml2js.Parser({ explicitArray: false })
parser.parseString(this.accessionXML, (err, results) => {
this.accessionJSON = results.accessions
})...
getJSONItem(itemNumber, callback) {
let oneItem
let items = this.accessionJSON.item.filter(item => {
return item.accession === itemNumber
})
if (items.length > 1) {
console.log('getJSONItem: ' + items.length + ' items for accession: ' + itemNumber)
}
callback(items[0])
}
After calling getJSONItem the JSON string values have unconverted entities
(' & ...)
Am I missing an obvious option to do this? What is the best way to get these converted?