Holy cow! I think I've got some code hiding away in a corner somewhere for processing RSS feeds that looks like that.
A really neat thing about XML retrieved with ajax, is that you can use all the element selecting functions as you would for regular html. So getElementsByTagName and querySelectorAll are rather useful here.
Here's some code that will enumerate the productCategory and productGroup elements, producing the following output:
-=== Software ===-
- Desktop OS
- Server OS
-=== dfg ===-
- dfg1
- dfg2
- dfg3
XHR finished loading: GET "http://localhost/snippets/sep18/xmlInput.xml".
function ajaxGet(url, onLoad, onError, resType=undefined)
{
var ajax = new XMLHttpRequest();
ajax.onload = function(){onLoad(this);}
ajax.onerror = function(){console.log("ajax request failed to: "+url);onError(this);}
ajax.responseType = resType;
ajax.open("GET",url,true);
ajax.send();
}
window.addEventListener('load', onDocLoaded, false);
function onDocLoaded(evt)
{
ajaxGet('xmlInput.xml', onLoaded, undefined);
function onLoaded(ajax)
{
var XML = ajax.responseXML;
var categories = XML.getElementsByTagName('productCategory');
var tmp = Array.from(categories);
tmp.forEach(
function(elem)
{
console.log( `-=== ${elem.getAttribute('name')} ===-` );
var groups = Array.from( elem.getElementsByTagName('productGroup') );
groups.forEach(
function(grp)
{
console.log( `- ${grp.getAttribute('name')}` );
}
);
}
);
}
}