Node To Parse Xml Using Xml2js
I am trying to parse and query for an element within an xml using xml2js. My xml string is as follows: var xml = 'Hello SomeData&l
Solution 1:
it works for me
var xml2js = require('xml2js');
var xml = "<config><test>Hello</test><data>SomeData</data></config>";
var extractedData = "";
var parser = new xml2js.Parser();
parser.parseString(xml, function(err,result){
//Extract the value from the data element
extractedData = result['config']['data'];
console.log(extractedData);
});
console.log("Note that you can't use value here if parseString is async; extractedData=", extractedData);
result:
SomeData
Note that you can'tuse value here if parseString is async; extractedData= SomeData
Post a Comment for "Node To Parse Xml Using Xml2js"