You can get close by selecting nodes. E.g. to select all elements at the 3rd level and on the way expanding all on the levels above you would use
app.select(
app.activeDocument.xmlElements.item(0) // the root element
.xmlElements.everyItem() // repeat this line for each nesting level
.xmlElements.everyItem() // and so forth
.getElements() // provide an array with the actual selectable items
);
Repeat for the indicated line for deeper levels. With the following snippet you could also select XML attributes of those elements without children:
.xmlAttributes.everyItem()
Finally deselect to clean up the selection highlights.
app.select(null);
Edit: For an arbitrary depth you can use a loop. It just should ensure there are elements in the XMLElement / XMLAttribute collections before asking for them. The resulting code:
var items = app.activeDocument.xmlElements.everyItem();
while( items.xmlElements.length ) {
items = items.xmlElements.everyItem();
app.select(items.getElements());
if( items.xmlAttributes.length )
app.select(items.xmlAttributes.everyItem().getElements());
}
app.select(null);