Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: XPATH DOM traverse html/xml

by mirod (Canon)
on Dec 08, 2009 at 16:11 UTC ( #811780=note: print w/ replies, xml ) Need Help??


in reply to XPATH DOM traverse html/xml

I don't know which module you use, but with XML::Twig you can use the xpath method like this, for example:

perl -MXML::Twig -E'my $t=XML::Twig->parse( "my.xml"); foreach my $e ($t->descendants( "#ELT")) { say $e->xpath; }'


Comment on Re: XPATH DOM traverse html/xml
Download Code
Replies are listed 'Best First'.
Re^2: XPATH DOM traverse html/xml
by benizi (Hermit) on Dec 09, 2009 at 06:18 UTC

    XML::Twig is one of the many things that keeps me using Perl. (It's one of the modules my personal 'M.pm' module loads -- 'M.pm' so I can do perl -MM -lwe ....) So, thanks again, mirod.

    The first thing that came to mind was:

    perl -MXML::Twig -E 'XML::Twig->new( twig_handlers => { _all_ => sub { say $_->xpath } })->parsefile(shift)'

    ...which isn't so different from what you wrote. But, the following has the benefit of not requiring the loading of the entire file (correct?):

    perl -MXML::Twig -E 'XML::Twig->new( start_tag_handlers => { _all_ => sub { say $_->xpath } })->parsefile(shift)'

      Absolutely, the way you wrote it is more efficient. I just went for the easiest way I could think of, not knowing enough about the OP's exact constraints.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2015-07-31 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (276 votes), past polls