ritvik_raj2012 has asked for the wisdom of the Perl Monks concerning the following question:

hi monks,
I need to find out XPATH for any given node in a XML document.if any node is given then the whole XPATH for that node from root should be printed.
  • Comment on finding XPATH for any node in a XML file

Replies are listed 'Best First'.
Re: finding XPATH for any node in a XML file
by ikegami (Patriarch) on Apr 20, 2012 at 16:27 UTC
Re: finding XPATH for any node in a XML file
by Anonymous Monk on Apr 20, 2012 at 14:29 UTC

      1.

      use XML::Twig ; XML::Twig->new( twig_handlers => { '*' => sub { print $_->xpath, "\n"; }, }, )->xparse( "somefile.xml" );

      2.

      use XML::Twig ; XML::Twig->new( start_tag_handlers => { '_all_' => sub { print $_->xpath, "\n"; }, }, )->xparse( "somefile.xml" );