How can I respond in XML using ExpressJS?

后端 未结 2 1304
遥遥无期
遥遥无期 2020-12-13 18:44

I have a simple code that gives a JSON response for a specific route. Here\'s my current code:

var express = require(\'express\')
  , async = require(\'async         


        
2条回答
  •  借酒劲吻你
    2020-12-13 18:57

    You can use any number of the XML libraries available on npm. Here's an example using the simply-named "xml" library:

    var xml = require('xml');
    
    response.set('Content-Type', 'text/xml');
    response.send(xml(name_of_restaurants));
    

    See the module's documentation for a description of how it converts JavaScript objects to XML. If you need things returned in a specific XML format, you'll have more work to do, of course.

提交回复
热议问题