I am trying to parse through an XML file in Node.js by using the xml2js library. However, I am not able to access the nested contents of that XML file. Here is how my XML file looks like:
<?xml version=\"1.0\" ?>
<ItemSearchResponse
xmlns=\"http://webservices.amazon.com/AWSECommerceService/2013-08-01\">
<OperationRequest>...</OperationRequest>
<Items>
<Item>
<LargeImage>..</LargeImage>
</Item>
<Item>...</Item>
<Item>...</Item>
<Item>...</Item>
</Items>
I am trying to access the LargeImage tag in this xml file. As of now, I am trying to access the sub-nodes by doing this:
var xml = response.responseBody; //this is an api call which returns the XML file
parser.parseString(xml, function (err, result) {//parser is an object of xml2js
console.log(result['ItemSearchResponse']['Items']);
});
//console.log("Raw response body: ", response.responseBody);
}).catch((err) => {
console.error("Something went wrong! ", err);
});
And for that this is getting printed on the console:
[ { Request: [ [Object] ],
TotalResults: [ '226308' ],
TotalPages: [ '22631' ],
MoreSearchResultsUrl:
[ 'https://www.amazon.in/gp/search?linkCode=xm2&SubscriptionId=AKIAIQWXVVSOIXRWDBIQ&keywords=tshirt&tag=theaedifex-21&creative=165953&url=search-alias%3Daws-amazon-aps&camp=2025' ],
Item:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } ]
I am trying to access the multiple objects at the end of Items. Any kind of solution or direction to my problem would be really helpful.