I have a xml file like this(pasted only a part of the xml)
<bitrate name="1000"> <track type="V"> <range> <rangeStartTime>1261287</range +StartTime> <rangeEndTime>1324271</rangeEn +dTime> </range> <range> <rangeStartTime>1324282</range +StartTime> <rangeEndTime>0.000</rangeEndT +ime> </range> </track> </bitrate>
I want to extract the value of 1st rangeStartTime
my $twig = XML::Twig->new( twig_roots => { "bitrate[\@name=\"1000\"]/trac +k[\@type=\"V\"]/range[1]/rangeStartTime" => \&update, }, ) ->parse($filename); print $value; sub update { my ($twig, $server) = @_; $value= $server->text; }
This gives me the 2nd rangeStartTime in the xml.

If i use the xpath like
"bitrate[\@name=\"1000\"]/track[\@type=\"V\"]/range[position() = 1]/ra +ngeStartTime"
I get an error
"unrecognized expression in handler: 'bitrate[@name="1000"]/track[@typ +e="V"]/range[position() = 1]/rangeStartTime' at try16.pl line 35"
I tried to use findnode() also
my $count = $t->findnodes("bitrate[\@name=\"1000\"]/track[\@type=\"V\" +]/range[position() = 1]/rangeStartTime");
It gives error like this
error in xpath expression bitrate[@name="1000"]/track[@type="V"]/range +[position() = 1]/rangeStartTime at position() = 1 at /usr/share/perl5 +/XML/Twig.pm line 3085
I have xml::xpath installed on my system
I am stuck on this for quite a while, any help would be appreciated.

Extra code tags added by GrandFather


In reply to XML::Twig - Using xpath with twig roots by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.