XML payload is received as a response from a third-party API request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 09:50 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 10:21 PM
Can you share how are you parsing it currently?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 10:25 PM
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
}