XML filter with parent nodes intact

Hi all.

Is there any obscure, standard E4X way of filtering XML so that the results are returned with the tree structure with all parents intact?

Similar to e.g. this:

var selectedNodes:XMLList = content..thumbnail;

But this returns only the matching nodes as a flat XMLList. I would like instead like to strip out all branches that don’t ultimately contain a thumbnail element, but maintain branch leading down to the matched node.

Like this:


<xml>
	<firstNode>
		<childNode></childNode>
		<childNode></childNode>
		<childNode></childNode>
	</firstNode>
	<secondNode>
		<unwantedChild></unwantedChild>
		<unwantedChild></unwantedChild>
		<unwantedChild></unwantedChild>
	</secondNode>
</xml>

And then if I filter based on node name “childNode”, this would be the result:


<xml>
	<firstNode>
		<childNode></childNode>
		<childNode></childNode>
		<childNode></childNode>
	</firstNode>
</xml>