2019-05-09 12:51:57 +00:00
|
|
|
// Copyright IBM Corp. 2017. All Rights Reserved.
|
2017-01-09 16:01:52 +00:00
|
|
|
// Node module: strong-error-handler
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2019-10-11 13:57:15 +00:00
|
|
|
const js2xmlparser = require('js2xmlparser');
|
2017-01-09 16:01:52 +00:00
|
|
|
|
2020-05-20 21:33:11 +00:00
|
|
|
module.exports = function sendXml(res, data, options) {
|
|
|
|
options = options || {};
|
|
|
|
// Xml always requires a root element.
|
|
|
|
// `options.rootProperty === false` is not honored
|
|
|
|
const root = options.rootProperty || 'error';
|
|
|
|
const content = js2xmlparser.parse(root, data);
|
2017-01-09 16:01:52 +00:00
|
|
|
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
res.end(content, 'utf-8');
|
|
|
|
};
|