What would be the best (preferably most efficient) method to do the following:
Consider I have an XML document as such:
<comments question_id="123">
<comment id="1">
This is the first comment
</comment>
<comment id="2">
This is the second comment
</comment>
</comments>
Now, given that I specify the “path” to each data-block, i.e. in this case:
path: /comments/comment
I would like to break up the document into n-number of sub-parts, in this case 2:
<comments question_id="123">
<comment id="1">
This is the first comment
</comment>
</comments>
<comments question_id="123">
<comment id="2">
This is the second comment
</comment>
</comments>
So, essentially, what I am trying to do is get each node produced by “/comments/comment”
, but also retain all “outer” parent nodes data.
EDIT:
Note: this needs to be dynamic, or generic. I.e. the above data xml is just an example. I want to be able to transform any xml document to this effect, given a “path” representing each data-node. And the rest is the outer body of the xml.