XML payload is received as a response from a third-party API request

shivaadapa
Tera Expert

Hi
"Suppose a large XML payload is received as a response from a third-party API request, and your scoped app requires parsing that payload. In that case, there might be instances where looping through multiple nodes might take a significant amount of time, resulting in an infinite loop affecting the instance resources. To avoid such scenarios, always keep a maximum counter/limit in your logic while parsing XML elements to break the loop once that upper limit is reached."
How can I set maximum counter/limit in your logic while parsing XML elements to break the loop once that upper limit is reached?

2 REPLIES 2

Dibyaratnam
Tera Sage

Can you share how are you parsing it currently?

Gurpreet07
Mega Sage

Hi,  I may not have understood the question correctly but if you think below can address your query then give it a try

1. Create a system property...    xml_max_iteration_limit      and set a value in it.      say 5000

2. When parsing the xml use a condition in that if the  child nodes length is greated than max limit then use max limit as length instead

 

var maxLength = gs.getProperty('xml_max_iteration_limit');

var childNodesLength = childNodes.length;

if(childNodesLength > maxLength )

childNodesLength = maxLength;

 

for(var i = 0; i< childNodesLength; i++{

// Parse child nodes here

 }