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?
您的name
变量是一个数组,请尝试以下操作:
var strinRes = result.root.More[0].MoreArray[0].name[0];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.