Вы можете использовать camaro для этой цели. напишите шаблон на основе xpath, чтобы указать, какие атрибуты вы хотели бы сохранить, как вы хотите назвать его в выводе json;что-то вроде ниже
![enter image description here](https://i.stack.imgur.com/3Hl74.png)
пример
const { transform } = require('camaro')
const fs = require('fs')
const xml = fs.readFileSync('examples/ean.xml', 'utf-8')
const template = {
cache_key: '/HotelListResponse/cacheKey',
hotels: ['//HotelSummary', {
hotel_id: 'hotelId',
name: 'name',
rooms: ['RoomRateDetailsList/RoomRateDetails', {
rates: ['RateInfos/RateInfo', {
currency: 'ChargeableRateInfo/@currencyCode',
non_refundable: 'boolean(nonRefundable = "true")',
price: 'number(ChargeableRateInfo/@total)'
}],
room_name: 'roomDescription',
room_type_id: 'roomTypeCode'
}]
}],
session_id: '/HotelListResponse/customerSessionId'
}
;(async function () {
const result = await transform(xml, template)
console.log(result)
})()