in reply to Re: XML::Twig - Using xpath with twig roots
in thread XML::Twig - Using xpath with twig roots

Thanks. Does findnodes() also not support the full Xpath? I see references that it does, but somehow it doesnt work for me.
  • Comment on Re^2: XML::Twig - Using xpath with twig roots

Replies are listed 'Best First'.
Re^3: XML::Twig - Using xpath with twig roots
by Khen1950fx (Canon) on Dec 19, 2011 at 23:58 UTC

    According to this post, findnodes() uses the full XPath engine. Also, I noticed that the use of position selectors like range[1] isn't supported on twig_handlers or twig_roots.

    Since you're dealing with a very, very small XML, I tried this and returned both rangeStartTimes. I cheated:)...
    #!/usr/bin/perl -l use strict; use warnings; use XML::Twig::XPath; $|=1; my $file = '/root/Desktop/bitrate.xml'; my $twig = XML::Twig::XPath->new( twig_roots => { "//range/rangeStartTime" => \&update }); $twig->parsefile($file); sub update { my ($twig, $server) = @_; print $server->text; }
    Here's the tidied XML:
    <?xml version="1.0" encoding="UTF-8"?> <bitrate name="1000"> <track type="V"> <range> <rangeStartTime>1261287</rangeStartTime> <rangeEndTime>1324271</rangeEndTime> </range> <range> <rangeStartTime>1324282</rangeStartTime> <rangeEndTime>0.000</rangeEndTime> </range> </track> </bitrate>
    Update: fixed typo