XPath is a way to select particular nodes out of an XML tree, but on its own it can't change the content of any of those nodes. If you use an expression to select the folder
element
/response/folder
then you'll get the whole of that element, including the case
children. You could select just the "leaf" elements under folder
using
/response/folder/*[not(*)]
which would give you a node set containing two elements (the TestOne
and the TestTwo
), but assembling those two elements into a new folder
element is not something XPath can do for you. You'll have to do that yourself using whatever facilities are provided by the language/tool you're using to evaluate the XPath expressions.