Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Want to fetch inner most child element first

by flexvault (Monsignor)
on Sep 23, 2015 at 13:21 UTC ( #1142804=note: print w/replies, xml ) Need Help??

in reply to Want to fetch inner most child element first

Welcom dharan,

    "...using XML::XPath..."

And the code that you are having a problem with is where?


"Well done is better than well said." - Benjamin Franklin

  • Comment on Re: Want to fetch inner most child element first

Replies are listed 'Best First'.
Re^2: Want to fetch inner most child element first
by dharan (Initiate) on Sep 23, 2015 at 13:39 UTC
    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), }

      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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-01-18 20:03 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (54 votes). Check out past polls.