# XML filter with parent nodes intact

**URL:** <https://forum.kirupa.com/t/xml-filter-with-parent-nodes-intact/304076>\
**Category:** flash\
**Created:** [February 1, 2010, 9:52am UTC](https://forum.kirupa.com/t/xml-filter-with-parent-nodes-intact/304076 "2010-02-01T09:52:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![oybrator](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/oybrator/32/1384_2.png) [@oybrator](https://forum.kirupa.com/u/oybrator)\
**Post date:** [February 1, 2010, 9:52am UTC](https://forum.kirupa.com/t/xml-filter-with-parent-nodes-intact/304076/1 "2010-02-01T09:52:54Z")

</div>

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:

```auto
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:

```auto

<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:

```auto

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

```
