Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Want to fetch inner most child element first

by dharan (Initiate)
on Sep 23, 2015 at 13:39 UTC ( [id://1142805]=note: print w/replies, xml ) Need Help??


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 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1142805]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-16 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found