Node.js remove root node from resulting XML using xml2js
I'm trying creating a XML from JSON obj and its giving me root element in the result, I tried setting the explicitRoot var parser = xml2js.Parser({explicitRoot:false});
to false but it does not remove the default root tag but just removing my orignal XML root tag (<VSAT></VSAT>)
Processing XML using xml2js
<?xml version="1.0" encoding="utf-8"?>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
Resulting XML:
<?xml version="1.0" encoding="utf-8"?>
<root>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
</root>
Any idea ?
full code
/*
NodeJS server
*/
var http = require('http');
var xml2js = require('xml2js');
var fs = require('fs');
var util = require('util');
var json,PORT=2000;
var server = http.createServer(function(request, response){
response.writeHead(200,{'Content-Type':'text/html'});
try{
var filedata = fs.readFileSync('vast_all.xml','ascii');
var parser = xml2js.Parser({explicitRoot:true});
parser.parseString(filedata.substring(0,filedata.length),function(err,result){
result.new = 'test';
json = JSON.stringify(result);
var builder = new xml2js.Builder({
xmldec:{ 'version': '1.0', 'encoding': 'UTF-8' },
cdata:true,
});
var xml = builder.buildObject(json);
response.write(json);
/*console.log(util.inspect(builder, false, null));*/
});
response.end();
}
catch(e){
console.log(e);
}
});
console.log("Server running at port "+PORT);
try{
server.listen(PORT);
}
catch(e){
console.log(e);
}
xml node.js
add a comment |
I'm trying creating a XML from JSON obj and its giving me root element in the result, I tried setting the explicitRoot var parser = xml2js.Parser({explicitRoot:false});
to false but it does not remove the default root tag but just removing my orignal XML root tag (<VSAT></VSAT>)
Processing XML using xml2js
<?xml version="1.0" encoding="utf-8"?>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
Resulting XML:
<?xml version="1.0" encoding="utf-8"?>
<root>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
</root>
Any idea ?
full code
/*
NodeJS server
*/
var http = require('http');
var xml2js = require('xml2js');
var fs = require('fs');
var util = require('util');
var json,PORT=2000;
var server = http.createServer(function(request, response){
response.writeHead(200,{'Content-Type':'text/html'});
try{
var filedata = fs.readFileSync('vast_all.xml','ascii');
var parser = xml2js.Parser({explicitRoot:true});
parser.parseString(filedata.substring(0,filedata.length),function(err,result){
result.new = 'test';
json = JSON.stringify(result);
var builder = new xml2js.Builder({
xmldec:{ 'version': '1.0', 'encoding': 'UTF-8' },
cdata:true,
});
var xml = builder.buildObject(json);
response.write(json);
/*console.log(util.inspect(builder, false, null));*/
});
response.end();
}
catch(e){
console.log(e);
}
});
console.log("Server running at port "+PORT);
try{
server.listen(PORT);
}
catch(e){
console.log(e);
}
xml node.js
Both JSON and XML should have a root element (unless the JSON is an array that is, but then you should not try to convert it to XML). It would be wise to provide an example JSON and the resulting XML in the question, just to illustrate it better.
– grochmal
Jul 7 '16 at 11:43
Wait, you're making the JSON->XML usingxml2js.Builder()
notxml2js.Parser()
, right?
– grochmal
Jul 7 '16 at 12:24
@grochmal right.
– AngularLearner
Jul 11 '16 at 7:00
add a comment |
I'm trying creating a XML from JSON obj and its giving me root element in the result, I tried setting the explicitRoot var parser = xml2js.Parser({explicitRoot:false});
to false but it does not remove the default root tag but just removing my orignal XML root tag (<VSAT></VSAT>)
Processing XML using xml2js
<?xml version="1.0" encoding="utf-8"?>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
Resulting XML:
<?xml version="1.0" encoding="utf-8"?>
<root>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
</root>
Any idea ?
full code
/*
NodeJS server
*/
var http = require('http');
var xml2js = require('xml2js');
var fs = require('fs');
var util = require('util');
var json,PORT=2000;
var server = http.createServer(function(request, response){
response.writeHead(200,{'Content-Type':'text/html'});
try{
var filedata = fs.readFileSync('vast_all.xml','ascii');
var parser = xml2js.Parser({explicitRoot:true});
parser.parseString(filedata.substring(0,filedata.length),function(err,result){
result.new = 'test';
json = JSON.stringify(result);
var builder = new xml2js.Builder({
xmldec:{ 'version': '1.0', 'encoding': 'UTF-8' },
cdata:true,
});
var xml = builder.buildObject(json);
response.write(json);
/*console.log(util.inspect(builder, false, null));*/
});
response.end();
}
catch(e){
console.log(e);
}
});
console.log("Server running at port "+PORT);
try{
server.listen(PORT);
}
catch(e){
console.log(e);
}
xml node.js
I'm trying creating a XML from JSON obj and its giving me root element in the result, I tried setting the explicitRoot var parser = xml2js.Parser({explicitRoot:false});
to false but it does not remove the default root tag but just removing my orignal XML root tag (<VSAT></VSAT>)
Processing XML using xml2js
<?xml version="1.0" encoding="utf-8"?>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
Resulting XML:
<?xml version="1.0" encoding="utf-8"?>
<root>
<VAST version="2.0">
<Ad id="72419"></Ad>
</VAST>
</root>
Any idea ?
full code
/*
NodeJS server
*/
var http = require('http');
var xml2js = require('xml2js');
var fs = require('fs');
var util = require('util');
var json,PORT=2000;
var server = http.createServer(function(request, response){
response.writeHead(200,{'Content-Type':'text/html'});
try{
var filedata = fs.readFileSync('vast_all.xml','ascii');
var parser = xml2js.Parser({explicitRoot:true});
parser.parseString(filedata.substring(0,filedata.length),function(err,result){
result.new = 'test';
json = JSON.stringify(result);
var builder = new xml2js.Builder({
xmldec:{ 'version': '1.0', 'encoding': 'UTF-8' },
cdata:true,
});
var xml = builder.buildObject(json);
response.write(json);
/*console.log(util.inspect(builder, false, null));*/
});
response.end();
}
catch(e){
console.log(e);
}
});
console.log("Server running at port "+PORT);
try{
server.listen(PORT);
}
catch(e){
console.log(e);
}
xml node.js
xml node.js
edited Jul 11 '16 at 7:19
AngularLearner
asked Jul 7 '16 at 11:40
AngularLearnerAngularLearner
3910
3910
Both JSON and XML should have a root element (unless the JSON is an array that is, but then you should not try to convert it to XML). It would be wise to provide an example JSON and the resulting XML in the question, just to illustrate it better.
– grochmal
Jul 7 '16 at 11:43
Wait, you're making the JSON->XML usingxml2js.Builder()
notxml2js.Parser()
, right?
– grochmal
Jul 7 '16 at 12:24
@grochmal right.
– AngularLearner
Jul 11 '16 at 7:00
add a comment |
Both JSON and XML should have a root element (unless the JSON is an array that is, but then you should not try to convert it to XML). It would be wise to provide an example JSON and the resulting XML in the question, just to illustrate it better.
– grochmal
Jul 7 '16 at 11:43
Wait, you're making the JSON->XML usingxml2js.Builder()
notxml2js.Parser()
, right?
– grochmal
Jul 7 '16 at 12:24
@grochmal right.
– AngularLearner
Jul 11 '16 at 7:00
Both JSON and XML should have a root element (unless the JSON is an array that is, but then you should not try to convert it to XML). It would be wise to provide an example JSON and the resulting XML in the question, just to illustrate it better.
– grochmal
Jul 7 '16 at 11:43
Both JSON and XML should have a root element (unless the JSON is an array that is, but then you should not try to convert it to XML). It would be wise to provide an example JSON and the resulting XML in the question, just to illustrate it better.
– grochmal
Jul 7 '16 at 11:43
Wait, you're making the JSON->XML using
xml2js.Builder()
not xml2js.Parser()
, right?– grochmal
Jul 7 '16 at 12:24
Wait, you're making the JSON->XML using
xml2js.Builder()
not xml2js.Parser()
, right?– grochmal
Jul 7 '16 at 12:24
@grochmal right.
– AngularLearner
Jul 11 '16 at 7:00
@grochmal right.
– AngularLearner
Jul 11 '16 at 7:00
add a comment |
3 Answers
3
active
oldest
votes
Set the headless
to true when instantiating Builder e.g.:
let builder = new xml2js.Builder({headless: true});
This worked for me. It removed the:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
But this is only supported from version 0.4.3
add a comment |
This is too long for a comment.
The correct way to create XML from JSON with xml2js
is using xml2js.Builder
. For example, in the following snippet the JSON is changed into an XML string and then parsed back to JSON:
var fs = require('fs');
var xml2js = require('xml2js');
var data = { VAST: { '$': { version: '2.0' }
, Ad: { '$': { id: '72419' }, content: "yay" } } };
console.log("the JSON");
console.log(JSON.stringify(data));
// the JSON
// {"VAST":{"$":{"version":"2.0"},"Ad":{"$":{"id":"72419"},"content":"yay"}}}
var builder = new xml2js.Builder();
var xml = builder.buildObject(data);
console.log("result from xml2js.builder");
console.log(xml); // this is a string
// result from xml2js.builder
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <VAST version="2.0">
// <Ad id="72419">
// <content>yay</content>
// </Ad>
// </VAST>
var parser = new xml2js.Parser();
parser.parseString(xml, function(err, result) {
console.log("result of parsing it back");
console.log(JSON.stringify(result));
console.log(result.VAST['Ad'][0]['$']['id']); // you can get the id back
});
// result of parsing it back
// {"VAST":{"$":{"version":"2.0"},"Ad":[{"$":{"id":"72419"},"content":["yay"]}]}}
// 72419
The parser adds an extra array ("Ad":[{"$"
) because you can have more than one Ad
tag (and this allows for a clean way to access things in node later).
Now, if you add this:
var badxml = builder.buildObject(xml);
console.log(badxml);
To the end of that snippet then you do get an XML with an extra root
element:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VAST version="2.0">
<Ad id="72419">
<content>yay</content>
</Ad>
</VAST></root>
But it is still quite different from what you are getting, since it is properly escaped.
I'm manipulating XML with xml2js and adding new nodes and then converting back it to XML (from JSON)
– AngularLearner
Jul 11 '16 at 7:05
add a comment |
you can't remove root node but you can change its name like this:
let builder = new xml2js.Builder({headless: true , explicitRoot : false , rootName :'Search_Query'});
let xml = builder.buildObject(req.param('Search_Query'));
This will change the root
to Search_Query
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38244545%2fnode-js-remove-root-node-from-resulting-xml-using-xml2js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Set the headless
to true when instantiating Builder e.g.:
let builder = new xml2js.Builder({headless: true});
This worked for me. It removed the:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
But this is only supported from version 0.4.3
add a comment |
Set the headless
to true when instantiating Builder e.g.:
let builder = new xml2js.Builder({headless: true});
This worked for me. It removed the:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
But this is only supported from version 0.4.3
add a comment |
Set the headless
to true when instantiating Builder e.g.:
let builder = new xml2js.Builder({headless: true});
This worked for me. It removed the:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
But this is only supported from version 0.4.3
Set the headless
to true when instantiating Builder e.g.:
let builder = new xml2js.Builder({headless: true});
This worked for me. It removed the:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
But this is only supported from version 0.4.3
answered Sep 5 '17 at 12:20
Ivan PandžićIvan Pandžić
177112
177112
add a comment |
add a comment |
This is too long for a comment.
The correct way to create XML from JSON with xml2js
is using xml2js.Builder
. For example, in the following snippet the JSON is changed into an XML string and then parsed back to JSON:
var fs = require('fs');
var xml2js = require('xml2js');
var data = { VAST: { '$': { version: '2.0' }
, Ad: { '$': { id: '72419' }, content: "yay" } } };
console.log("the JSON");
console.log(JSON.stringify(data));
// the JSON
// {"VAST":{"$":{"version":"2.0"},"Ad":{"$":{"id":"72419"},"content":"yay"}}}
var builder = new xml2js.Builder();
var xml = builder.buildObject(data);
console.log("result from xml2js.builder");
console.log(xml); // this is a string
// result from xml2js.builder
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <VAST version="2.0">
// <Ad id="72419">
// <content>yay</content>
// </Ad>
// </VAST>
var parser = new xml2js.Parser();
parser.parseString(xml, function(err, result) {
console.log("result of parsing it back");
console.log(JSON.stringify(result));
console.log(result.VAST['Ad'][0]['$']['id']); // you can get the id back
});
// result of parsing it back
// {"VAST":{"$":{"version":"2.0"},"Ad":[{"$":{"id":"72419"},"content":["yay"]}]}}
// 72419
The parser adds an extra array ("Ad":[{"$"
) because you can have more than one Ad
tag (and this allows for a clean way to access things in node later).
Now, if you add this:
var badxml = builder.buildObject(xml);
console.log(badxml);
To the end of that snippet then you do get an XML with an extra root
element:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VAST version="2.0">
<Ad id="72419">
<content>yay</content>
</Ad>
</VAST></root>
But it is still quite different from what you are getting, since it is properly escaped.
I'm manipulating XML with xml2js and adding new nodes and then converting back it to XML (from JSON)
– AngularLearner
Jul 11 '16 at 7:05
add a comment |
This is too long for a comment.
The correct way to create XML from JSON with xml2js
is using xml2js.Builder
. For example, in the following snippet the JSON is changed into an XML string and then parsed back to JSON:
var fs = require('fs');
var xml2js = require('xml2js');
var data = { VAST: { '$': { version: '2.0' }
, Ad: { '$': { id: '72419' }, content: "yay" } } };
console.log("the JSON");
console.log(JSON.stringify(data));
// the JSON
// {"VAST":{"$":{"version":"2.0"},"Ad":{"$":{"id":"72419"},"content":"yay"}}}
var builder = new xml2js.Builder();
var xml = builder.buildObject(data);
console.log("result from xml2js.builder");
console.log(xml); // this is a string
// result from xml2js.builder
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <VAST version="2.0">
// <Ad id="72419">
// <content>yay</content>
// </Ad>
// </VAST>
var parser = new xml2js.Parser();
parser.parseString(xml, function(err, result) {
console.log("result of parsing it back");
console.log(JSON.stringify(result));
console.log(result.VAST['Ad'][0]['$']['id']); // you can get the id back
});
// result of parsing it back
// {"VAST":{"$":{"version":"2.0"},"Ad":[{"$":{"id":"72419"},"content":["yay"]}]}}
// 72419
The parser adds an extra array ("Ad":[{"$"
) because you can have more than one Ad
tag (and this allows for a clean way to access things in node later).
Now, if you add this:
var badxml = builder.buildObject(xml);
console.log(badxml);
To the end of that snippet then you do get an XML with an extra root
element:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VAST version="2.0">
<Ad id="72419">
<content>yay</content>
</Ad>
</VAST></root>
But it is still quite different from what you are getting, since it is properly escaped.
I'm manipulating XML with xml2js and adding new nodes and then converting back it to XML (from JSON)
– AngularLearner
Jul 11 '16 at 7:05
add a comment |
This is too long for a comment.
The correct way to create XML from JSON with xml2js
is using xml2js.Builder
. For example, in the following snippet the JSON is changed into an XML string and then parsed back to JSON:
var fs = require('fs');
var xml2js = require('xml2js');
var data = { VAST: { '$': { version: '2.0' }
, Ad: { '$': { id: '72419' }, content: "yay" } } };
console.log("the JSON");
console.log(JSON.stringify(data));
// the JSON
// {"VAST":{"$":{"version":"2.0"},"Ad":{"$":{"id":"72419"},"content":"yay"}}}
var builder = new xml2js.Builder();
var xml = builder.buildObject(data);
console.log("result from xml2js.builder");
console.log(xml); // this is a string
// result from xml2js.builder
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <VAST version="2.0">
// <Ad id="72419">
// <content>yay</content>
// </Ad>
// </VAST>
var parser = new xml2js.Parser();
parser.parseString(xml, function(err, result) {
console.log("result of parsing it back");
console.log(JSON.stringify(result));
console.log(result.VAST['Ad'][0]['$']['id']); // you can get the id back
});
// result of parsing it back
// {"VAST":{"$":{"version":"2.0"},"Ad":[{"$":{"id":"72419"},"content":["yay"]}]}}
// 72419
The parser adds an extra array ("Ad":[{"$"
) because you can have more than one Ad
tag (and this allows for a clean way to access things in node later).
Now, if you add this:
var badxml = builder.buildObject(xml);
console.log(badxml);
To the end of that snippet then you do get an XML with an extra root
element:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VAST version="2.0">
<Ad id="72419">
<content>yay</content>
</Ad>
</VAST></root>
But it is still quite different from what you are getting, since it is properly escaped.
This is too long for a comment.
The correct way to create XML from JSON with xml2js
is using xml2js.Builder
. For example, in the following snippet the JSON is changed into an XML string and then parsed back to JSON:
var fs = require('fs');
var xml2js = require('xml2js');
var data = { VAST: { '$': { version: '2.0' }
, Ad: { '$': { id: '72419' }, content: "yay" } } };
console.log("the JSON");
console.log(JSON.stringify(data));
// the JSON
// {"VAST":{"$":{"version":"2.0"},"Ad":{"$":{"id":"72419"},"content":"yay"}}}
var builder = new xml2js.Builder();
var xml = builder.buildObject(data);
console.log("result from xml2js.builder");
console.log(xml); // this is a string
// result from xml2js.builder
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <VAST version="2.0">
// <Ad id="72419">
// <content>yay</content>
// </Ad>
// </VAST>
var parser = new xml2js.Parser();
parser.parseString(xml, function(err, result) {
console.log("result of parsing it back");
console.log(JSON.stringify(result));
console.log(result.VAST['Ad'][0]['$']['id']); // you can get the id back
});
// result of parsing it back
// {"VAST":{"$":{"version":"2.0"},"Ad":[{"$":{"id":"72419"},"content":["yay"]}]}}
// 72419
The parser adds an extra array ("Ad":[{"$"
) because you can have more than one Ad
tag (and this allows for a clean way to access things in node later).
Now, if you add this:
var badxml = builder.buildObject(xml);
console.log(badxml);
To the end of that snippet then you do get an XML with an extra root
element:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VAST version="2.0">
<Ad id="72419">
<content>yay</content>
</Ad>
</VAST></root>
But it is still quite different from what you are getting, since it is properly escaped.
answered Jul 7 '16 at 13:03
grochmalgrochmal
1,85021222
1,85021222
I'm manipulating XML with xml2js and adding new nodes and then converting back it to XML (from JSON)
– AngularLearner
Jul 11 '16 at 7:05
add a comment |
I'm manipulating XML with xml2js and adding new nodes and then converting back it to XML (from JSON)
– AngularLearner
Jul 11 '16 at 7:05
I'm manipulating XML with xml2js and adding new nodes and then converting back it to XML (from JSON)
– AngularLearner
Jul 11 '16 at 7:05
I'm manipulating XML with xml2js and adding new nodes and then converting back it to XML (from JSON)
– AngularLearner
Jul 11 '16 at 7:05
add a comment |
you can't remove root node but you can change its name like this:
let builder = new xml2js.Builder({headless: true , explicitRoot : false , rootName :'Search_Query'});
let xml = builder.buildObject(req.param('Search_Query'));
This will change the root
to Search_Query
add a comment |
you can't remove root node but you can change its name like this:
let builder = new xml2js.Builder({headless: true , explicitRoot : false , rootName :'Search_Query'});
let xml = builder.buildObject(req.param('Search_Query'));
This will change the root
to Search_Query
add a comment |
you can't remove root node but you can change its name like this:
let builder = new xml2js.Builder({headless: true , explicitRoot : false , rootName :'Search_Query'});
let xml = builder.buildObject(req.param('Search_Query'));
This will change the root
to Search_Query
you can't remove root node but you can change its name like this:
let builder = new xml2js.Builder({headless: true , explicitRoot : false , rootName :'Search_Query'});
let xml = builder.buildObject(req.param('Search_Query'));
This will change the root
to Search_Query
answered Jan 1 at 6:45
Salahudin MalikSalahudin Malik
8012
8012
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38244545%2fnode-js-remove-root-node-from-resulting-xml-using-xml2js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Both JSON and XML should have a root element (unless the JSON is an array that is, but then you should not try to convert it to XML). It would be wise to provide an example JSON and the resulting XML in the question, just to illustrate it better.
– grochmal
Jul 7 '16 at 11:43
Wait, you're making the JSON->XML using
xml2js.Builder()
notxml2js.Parser()
, right?– grochmal
Jul 7 '16 at 12:24
@grochmal right.
– AngularLearner
Jul 11 '16 at 7:00