I have used many xml parsers till now, but non of them helps me to achieve my objective. A list of parsers that I've used is xml-body-parser
, xml2js
, libxmljs
and xamel
.
I want to do following things
- Parse XML and insert all elements one by one to an array (obviously using a loop)
- Update attributes of a specific element, no matter whatever it's depth is
- Preserve the sequence of xml nodes as they were before parsing
- response the updated xml
Till now, I've just accomplished to send xml and then response xml, nothing else
Code till now is
var express = require("express"),
bodyParser = require('body-parser');
require("body-parser-xml")(bodyParser);
var xml2js = require('xml2js');
var builder = new xml2js.Builder;
var app = express();
var util = require('util');
app.use(bodyParser.xml({
xmlParseOptions: {
normalize: false,
normalizeTags: false,
explicitArray: false
}
}));
var XmlPosted;
app.post('/users', function (req, res, body) {
XmlPosted = req.body;
console.log();
res.send(builder.buildObject(req.body));
res.status(200).end();
});
app.listen(4000);
This code works fine for me, things done in this code are
Updated response is sent