I am using a protractor application with typescript where I am converting an XML file to JSON format; I have a few questions :
Here is the code in the source.ts file:
{
var parseString = require('xml2js').parseString;
var xml = "<root><Copy><Home>true</Home></Copy><More><MoreArray><name>A</name></MoreArray><MoreArray><name>B</name></MoreArray></More></root>"
parseString(xml, function (err, result) {
var strinRes = result.root.More[0].MoreArray[0].name;
console.dir(strinRes.toUpperCase());
});
}
The output is : TypeError: strinRes.toUpperCase is not a function
The problem is strinRes is coming as [A] instead of A. This happens only with xml2js library and also "More" is represented as an array instead of an object.
Now, how do I parse this and print uppercase of A using same 'xml2js' library?
Your
name
variable is an array, try the following: