Transform xml string to JSON using the given template powered by XPath where:
xml
- the input xml stringtemplate
- the XPath template object, powered by XPath.
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)
})()
Not yet implemented
Transform xml string to JSON where:
xml
- the input xml string
const { toJson } = require('camaro')
const fs = require('fs')
const xml = fs.readFileSync('examples/ean.xml', 'utf-8')
;(async function () {
const result = await toJson(xml)
console.log(result)
})()
Pretty print xml string where:
xml
- the input xml stringoptions
- an optional object with the following optional keys:indentSize
- a number of space to use for indenting
const { prettyPrint } = require('camaro')
const fs = require('fs')
const xml = fs.readFileSync('examples/ean.xml', 'utf-8')
;(async function () {
const result = await prettyPrint(xml, { indentSize: 4 })
console.log(result)
})()