Expressjs response as JSON and Xml

后端 未结 2 1145
眼角桃花
眼角桃花 2021-01-06 09:27

What i am doing:: I am trying to generate json and xml output for a dataset from database

Express Code:: Here i am trying for JSON response

2条回答
  •  渐次进展
    2021-01-06 09:50

    So I've looked around for a better object-to-XML mapper for you. I tried three before I found one that I liked (it's easy-to-use, and it makes sense for your application). Ditch the old one, and use object-to-xml instead:

    var o2x = require('object-to-xml');
    
    response.set('Content-Type', 'text/xml');
    response.send(o2x({
        '?xml version="1.0" encoding="utf-8"?' : null,
        restaurants: {
            restaurant: name_of_restaurants
        }
    }));
    

提交回复
热议问题