in reply to Re: Want to fetch inner most child element first
in thread Want to fetch inner most child element first

Thanks flex for swift reply, below is the code and not sure how to proceed further.
use XML::XPath; my $xp = XML::XPath->new(filename => 'mathml.txt'); my $nodeset = $xp->find('/mml:math/*'); foreach my $node ($nodeset->get_nodelist) { $l = XML::XPath::XMLParser::as_string($node), }

Replies are listed 'Best First'.
Re^3: Want to fetch inner most child element first
by locked_user sundialsvc4 (Abbot) on Sep 23, 2015 at 17:52 UTC

    The XPath expression that you have written merely matches the outermost node.   What you might want to use here are axes.

    Try something like this:   (extemporaneous answer, check it yourself)

    //xml:msub[count(descendant::xml:msub) = 0] to retrieve all msubs who do not have any descendants of the same type.   These must be the leaves of the structure.

    Now, for each of these, perform a separate query for ancestor::xml:msub which will return an ordered list (from closest to farthest, or is it the other way around?) of all ancestors back to the top of the tree.