To get the specific kind of structured output you have provided the
example for (parent\child\grand-child) etc you'll probably have to load
the xml file into an XML DOM of some sort and 'walk your way' through it
iteratively building the path to each node-field as you go. You could
use the nodeName properties.
This kind of iteration I usually use
two functions, one to start off the routine, and the other as a
recursive processing of a node which calls itself.