var dataset = job.getDataset("Xml");
var xml = new Document(dataset.getPath());
var nodeList = xml.evalToNodes("/Orders/Order/Products/Product");
s.log(1, "Found: " + nodeList.length); //This works
for(var i = 1; i < nodeList.length + 1; i++){
var node = nodeList.at(i);
var code = node.getValue(); //This is not working
s.log(1, code);
}
Expected result in log
AAAAA
BBBBB
I don't get any suggestions when I write a dot (.) after "node" and get the error getValue(); is not a function.
Then to loop through them your for loop needs to start from 0 and you need to use the getFirstChild() function to be able to get to the value of the node. See below code that loops through logs the "code" nodes:
var dataset = job.getDataset("Xml");
var xml = new Document(dataset.getPath());
var nodeList = xml.evalToNodes("/Orders/Order/Product/code");
s.log(1, "Found: " + nodeList.length); //This works
for (var i = 0; i < nodeList.length; i++) {
var node = nodeList.at(i);
var code = node.getFirstChild().getValue(); //This is not working
s.log(1, code);
}
Then to loop through them your for loop needs to start from 0 and you need to use the getFirstChild() function to be able to get to the value of the node. See below code that loops through logs the "code" nodes:
var dataset = job.getDataset("Xml");
var xml = new Document(dataset.getPath());
var nodeList = xml.evalToNodes("/Orders/Order/Product/code");
s.log(1, "Found: " + nodeList.length); //This works
for (var i = 0; i < nodeList.length; i++) {
var node = nodeList.at(i);
var code = node.getFirstChild().getValue(); //This is not working
s.log(1, code);
}