Hi! I'm parsing big XML file with XPathExpression selection for some nodes existing at various depth levels.
What is the easiest way to export selected nodes to separate XML file, preserving all direct-ancestors nodes (and their attributes)? C# is preferred.
Example source XML :
<a>
<x>
<b>
<c/>
<z/>
</b>
<c/>
</a>
<c/>
<d><e/></d>
Expected target XML for filtering againts "c" nodes
<a>
<b>
<c/>
</b>
<c/>
</a>
<c/>
EDIT: I'm using XPathExpression and XPathNodeIterator because there is additional logic for testing if given node should be inculded in result XML, XPathExpression alone is not enough. So basically I have array of matching XPathNavigator elements, which I want to save to XML with ancestor structure.