How can I respond in XML using ExpressJS?

只愿长相守 提交于 2019-12-02 19:00:31

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.

Christopher Dyke

As an update to this, it looks like res.type should be used instead as res.set does not give the same results.

res.type('application/xml');

More information can be found in the API reference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!