getChildNodeIterator() iteration more than no of entries

priyankapalaska
Giga Contributor

Hi,

I have request body, where multiple nodes can be there in request body xml. But when I am iterating it using getChildNodeIterator(), it is iterating more times than number of entries parent node has. 

In the below scenario, logs occurring 6-7 times, when Request body has only one <x:systemResponse> node. 

I even tried replacing the statement var sysResp = xmlDoc.getNode('//x:targetResponse') by var sysResp = xmlDoc.getNode('//x:systemResponse'), but same situation was there. 

Request Body XML:

<x:execute>
<x:targetResponse>
<!-- 1 or more repetitions: -->
<x:systemResponse>
<x:system>SAP</x:system>
<x:type>S</x:type>
<x:message>Error Removed</x:message>
</x:systemResponse>
</x:targetResponse>
</x:execute>
 
Processing Script:
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(reqXML);
var sysResp = xmlDoc.getNode('//x:targetResponse');
var iter = sysResp.getChildNodeIterator();

while(iter.next()) {
var system=xmlDoc.getNodeText('//x:system');
var type=xmlDoc.getNodeText('//x:type');
var msg=xmlDoc.getNodeText('//x:message');
gs.info("System = "+system+"\nType = "+type+"\nMsg = "+msg);
}
 
 
Appreciate your quick response. 
 
Thanks you.