1

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?

Reza Mousavi
  • 4,420
  • 5
  • 31
  • 48
user1400915
  • 1,933
  • 6
  • 29
  • 55

1 Answers1

1

Your name variable is an array, try the following:

var strinRes = result.root.More[0].MoreArray[0].name[0];
Trent
  • 4,208
  • 5
  • 24
  • 46
mehta-rohan
  • 1,373
  • 1
  • 14
  • 19