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
Those <0> tags are there because you are embedding an array into 'restaurants'. Instead of that, try to name every restaurant as an object array:
...
response.send(xml({restaurants:[
name_of_restaurants.map(function(r){
return { restaurant_name? :
[
{ Buf_Type_Id: r.Buf_Type_Id },
{ Buf_Type_Name: r.Buf_Type_Name }
]
})
]}));
...
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
}
}));