#!/usr/bin/perl
use strict;
use warnings;
use XML::XPath;
use XML::XPath::XMLParser;
my $xp = XML::XPath->new(filename => 'test_x.xml');
foreach my $row ($xp->findnodes('/HOME/Trans')) {
# extract from the XML
my $trans = $row->find('//@ID')->string_value;
my $cert = $row->find('Cert')->string_value;
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-$bdate - 7-$no - 8-$state - 9-$ssss - 10-$train -
11-$volume - 12-$cno - 13-$id\n";
}
}
> perl ./xp.pl test_x.xml
1-0164754 - 2-8280164754 - 3-DELTA1 - 4-Joe - 5-Frost -
6-19650420 -7-X0000000 - 8-RI - 9-07 - 10-N -
11-N - 12- - 13-
1-0164754 - 2-8280164754 - 3-DELTA2 - 4-MARY - 5-FROST -
6-19861107 - 7-Y0000000 - 8-NY - 9-00 - 10-Y -
11-N - 12-153 - 13-WC204338
|