简体   繁体   中英

How can i return an XML file corresponding to a URL request in node.js?

I have a URL like www.xxx.com/get-xml-content . I want to send an XML file as a response to this URL request.

<?xml version="1.0" encoding="UTF-8"?>
   <response>
      <playtext>I lov u</playtext>
   </response>

The XML I created will looks like above. I want to send this XML as a response to the given URL. How can it be possible in Node.js?

There are lots of libraries which can help you serve a xml as response. Here is one, which can help you

https://www.npmjs.com/package/xml

var xml = require('xml');

response.set('Content-Type', 'text/xml');
response.send(xml(yourobj));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM