All, It has been awhile since I've posted. Hopefully, someone can help me with the problem I'm having in my while loop. I have provided my script and highlighted where the problem is.
Now, what am I trying to do. I have an XML document that I have to parse. I can parse everything, except for multiple drivers and vehicles. Everything I run this I only get one driver when I have two drivers. The beginning tag is <driver id=> (what I'm searching off of). The same with vehicles. when I set my counter and everything, it is not incramenting and just dumping after the first read through the XML.
So my question to you is "What is the problem with my recursive items"
Thanks again and please help.
#C:\PERL\bin\perl.exe -w #****PACKAGES****# use strict; use DBI; use DBD::Oracle qw(:ora_types); use XML::Parser; ##****END PACKAGES****# #****VARIABLES****# my $username = 'system'; my $password = ''; my $database = "dbi:Oracle:<DB NAME>"; my $oradbh; my $xmlSQL; my $sqlXML; my $xmldatafile = "E:\\<companyname>\\PERLFiles\\trash\\xmldata.xml"; my $datadump = "E:\\<companyname>\\PERLFiles\\trash\\extract.txt"; my $idNum=1; my $driverCount=0; my $vehicleCount=0; my @policyInfo; my @driversInfo; my @vehiclesInfo; #****END VARIABLES****# #****PROGRAM****# $oradbh = DBI->connect($database,$username,$password, {RaiseError => 1, PrintError => 0}) or die ($DBI::errstr, "\n"); #Sets the Long Read Length to accomendate the XML in the RFI_XML colum +n $oradbh -> {LongReadLen} = 30000*256; #SQL setup to extract the XML data from the 8i database $xmlSQL = qq(select rfi_xml from webrater_owner.quote where rownum bet +ween 1 and 50); $sqlXML = $oradbh->prepare($xmlSQL); $sqlXML -> execute(); my ($xml_sql_data); $sqlXML -> bind_columns(undef, \$xml_sql_data); #Write out all the XML data from RFI_XML to a text/xml file open(FILE,"> $xmldatafile") or die "Unable to open $xmldatafile : $!\n +"; while($sqlXML -> fetch()) { print FILE $xml_sql_data; } close(FILE) or warn "Unable to close $xmldatafile: $!\n"; $sqlXML -> finish(); #Finish the SQL command $oradbh -> disconnect; #Disconnect from the database open(FILE, "$xmldatafile") or die "Unable to open $xmldatafile : $!\n" +; open(FILE2, "> $datadump") or die "Unable to open $datadump : $!\n"; print FILE2 "IDNum|Quote#|Effective Date|Last Name|First Name|Address| +City|State|Zip|Driver0 Last Name|Driver0 First Name|Sex|Marital Statu +s|DOB|License Number|License State|Status|Driver#|Year|Make|Model|VIN +|Vehicle#\n"; while(<FILE>) { if (/^<rfi>/) { #print "new record set\n"; } elsif(m[(<.*?>)(.*?)(</.*?>)]x) #$1..$3 { if ($1 eq '<WebId>') { $policyInfo[0] = $2; } if ($1 eq '<effectiveDate>') { $policyInfo[1] = $2; } if ($1 eq '<LastName>') { $policyInfo[2] = $2; } if ($1 eq '<FirstName>') { $policyInfo[3] = $2; } if ($1 eq '<applicantAddress1>') { $policyInfo[4] = $2; } if ($1 eq '<applicantCity>') { $policyInfo[5] = $2; } if ($1 eq '<applicantState>') { $policyInfo[6] = $2; } if ($1 eq '<applicantZip>') { $policyInfo[7] = $2; } *****PROBLEM START***** if (/^<driver id=/) #get driver info { print "found driver\n"; if($driverCount > 0) { #$driverCount++; @driversInfo = (); #clear the array for driverInfo print "array cleared\n"; } } elsif(m[(<.*?>)(.*?)(</.*?>)]x) { if($1 eq '<lastName>') { $driversInfo[0] = $2; } if($1 eq '<firstName>') { $driversInfo[1] = $2; } if($1 eq '<sex>') { if($2 eq 'male') { $driversInfo[2] = 'M'; } else { $driversInfo[2] = 'F'; } } if($1 eq '<maritalStatus>') { $driversInfo[3] = $2; } if($1 eq '<Birth-Date>') { $driversInfo[4] = $2; } if($1 eq '<License-No>') { $driversInfo[5] = $2; } if($1 eq '<License-State>') { $driversInfo[6] = $2 } if($1 eq '<Rate-Status>') { $driversInfo[7] = $2; } } elsif(/<\/driver>/) { $driverCount++; print "New Driver Number $driverCount\n"; } *****PROBLEM END***** if(/^<vehicle /) #Get vehicle information { #Left blank for a reason } elsif(m[(<.*?>)(.*?)(</.*?>)]x) { if($1 eq '<year>') { $vehiclesInfo[0] = $2; } if($1 eq '<make>') { $vehiclesInfo[1] = $2; } if($1 eq '<model>') { $vehiclesInfo[2] = $2; } if($1 eq '<vin>') { $vehiclesInfo[3] = $2; } } elsif(/^<\/vehicle>/) { #Left blank for a reason } # print "$quote|$effectdate|$lastname|$firstname|$appAdd|$app +City|$appState|$appZip\n"; } elsif(/^<\/rfi>/) { print "\n@policyInfo\n"; print "Driver Number: $driverCount\n"; print "@driversInfo\n"; print "Vehicle Number: $vehicleCount\n"; print "@vehiclesInfo\n"; #print "$idNum|$policyInfo[0]|$policyInfo[1]|$policyInfo[2]|$p +olicyInfo[3]|$policyInfo[4]|$policyInfo[5]|$policyInfo[6]|$policyInfo +[7]|$driversInfo[0]|$driversInfo[1]|$driversInfo[2]|$driversInfo[3]|$ +driversInfo[4]|$driversInfo[5]|$driversInfo[6]|$driversInfo[7]|$drive +rCount|$vehiclesInfo[0]|$vehiclesInfo[1]|$vehiclesInfo[2]|$vehiclesIn +fo[3]|$vehicleCount\n"; #$idNum++; } } close(FILE); close(FILE2); #****END PROGRAM****#
Thanks in advance and any adjustments will be welcome.
thanks,
Bobby
bobby.curtis@ipacc.com

In reply to While in XML document by curtisb

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.