Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have successfully read an xml file, gotten some info and stored it in a variable. Then I used the information in the variable to system grep another xml file, and store that in a variable. I want to use XPATH to get some info from that second XML, but can't. It gives the following errors:

Use of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/XML/Parser/ line 474.

and ..

no element found at line 1, column 0, byte -1: 28^ 7157840 at /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/XML/ line 187

Here is the code:

#!/usr/bin/perl -w use strict; use warnings; use XML::XPath; use MIME::Lite::TT; use File::Copy; use File::Find; use File::Grep qw( fgrep fmap fdo ); my $file = '/home/jramirez/20120811_XML_Reader_837/test.xml'; my $xp = XML::XPath->new(filename => $file); my $icncount = 1; my $transactioncount = 0; my $billedamount = 0; my $PayerName3 = ''; my $ICN = ''; my $BillingProvider = ''; my $line = ''; my $cmd = ''; my $Name = ''; my $xmlpath = ''; my $xmlname = ''; print $file . "\n"; print $xp . "\n"; foreach my $InterchangeControlHeader ($xp->find('//InterchangeControlH +eader')->get_nodelist){ my $InterchangeControlNumber13 = $InterchangeControlHeader->find(' +@InterchangeControlNumber13')->string_value; $ICN = $InterchangeControlNumber13 } foreach my $Transaction837P ($xp->find('//Transaction837P')->get_nodel +ist){ my $BillingProviderIdentifier9 = $Transaction837P->find('BillingPr +oviderHierarchicalLevelLoop/BillingProviderNameLoop/BillingProviderNa +me/@BillingProviderIdentifier9')->string_value; $BillingProvider = $BillingProviderIdentifier9; $PayerName3 = $Transaction837P->find('SubscriberHierarchicalLevelL +oop/PayerNameLoop/PayerName/@PayerName3')->string_value; $transactioncount++; } foreach my $ServiceLineNumberLoop ($xp->find('//ServiceLineNumberLoop' +)->get_nodelist){ my $AssignedNumberLine = $ServiceLineNumberLoop->find('Service +LineNumber/@AssignedNumber1')->string_value; my $LineItemChargeAmount2 = $ServiceLineNumberLoop->find('Prof +essionalService/@LineItemChargeAmount2')->string_value; if ($LineItemChargeAmount2 eq '') { $LineItemChargeAmount2 = 0; } $billedamount += $LineItemChargeAmount2; } print 'Billing Provider: ' . $BillingProvider . "\n"; print 'ICN: ' . $ICN . "\n"; print 'Payer: ' . $PayerName3 . "\n"; print 'Total Number Invoices: ' . $transactioncount . "\n"; print 'Total Billed: ' . $billedamount . "\n"; my $SESXML = `find /home/jramirez/PayerDownload/SES/backup/*xml -maxde +pth 1 -type f -exec grep -q $ICN '{}' ';' -exec echo '{}' ';' `; chomp $SESXML; my $sesxp = XML::XPath->new(filename => $SESXML); foreach my $interchange ($sesxp->find('//Interchange')->get_nodelist){ $Name = $interchange->find('Accept/@Name')->string_value; print $Name . "\n"; print "I think we got 'em, but we dont!" . "\n"; }

The objective is to read the first xml, gather unique identifiers that help me find the second xml. Once the second xml is found, i want to XPATH the info I need from it into variables. Then I'll use the variables to generate a simple txt report.

I printed out the $xp and $sesxp variables and noted that they have the same value, and guess I should clear that? can't find how to, must be googling the wrong terms.

I humbly ask for help.

In reply to XML::XPath=HASH(0x10c4e230) is persistent by medirecpr

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (2)
    As of 2018-05-25 01:42 GMT
    Find Nodes?
      Voting Booth?