in reply to XML Path and Perl

Do you want the first child? The last child? All the kids? If just the first:

my $xref = $row->find('AD[1]/@XREF')->string_value;
If just the last:
my $xref = $row->find('AD[last()]/@XREF')->string_value;
If all ... well ... that's where my XPATH foo breaks down.

-derby

Replies are listed 'Best First'.
Re^2: XML Path and Perl
by Anonymous Monk on Feb 25, 2008 at 20:40 UTC
    How would I print the values for all the nodes, like this node shows twice, <AD XREF...>, and all the nodes after that.
Re^2: XML Path and Perl
by Anonymous Monk on Feb 25, 2008 at 20:33 UTC
    I have to get everything!

      Dude ... it's right there in the first couple of lines of XML::XPath:

      my $nodeset = $row->find('AD'); foreach my $node ( $nodeset->get_nodelist ) { my $xref = $node->find( '@XREF' )->string_value; my $fname = $node->find( 'FName')->string_value; my $lname = $node->find('LName')->string_value; my $bdate = $node->find('BDate')->string_value; my $no = $node->find('No')->string_value; my $state = $node->find('State')->string_value; my $ssss = $node->find('SSSS')->string_value; my $train = $node->find('Train')->string_value; my $volume = $node->find('Volume')->string_value; my $cno = $node->find('CNo')->string_value; my $id = $node->find('ID')->string_value; print "1-$trans - 2-$cert - 3-$xref - 4-$fname - 5-$lname - 6-$b +date - 7-$no - 8-$state - 9-$ssss - 10-$train - 11-$volume - 12- +$cno - 13-$id\n"; }

      but then again ... I prefer to use XSLT for stuff like this ... I love the pain

      -derby
        I dont know how you can get this code to work with the code above.