Hello Monks I am trying to extract information from xml file. The XML file looks like:
<?xml version="1.0"?> <reports> <report> <report-name>POSM1M029</report-name> <source-file id='1'> <source-file-path></source-file-path> </source-file> <destination-file id='1'> <destination-file-path></destination-file-path> </destination-file> </report> <report> <report-name>CNAM1D001</report-name> <source-file id='1'> <source-file-path>G:\Interfaces\ApplnData\DENVER_TRAN\Navi +Sys\Input\EXPORT_CFM.txt</source-file-path> </source-file> <destination-file id='1'> <destination-file-path>L:\Enterprise Reports\Input Files\ +ipCNAM1D001Confirm.txt</destination-file-path> </destination-file> <source-file id='2'> <source-file-path>G:\Interfaces\ApplnData\DENVER_TRAN\Navi +sys\Input\EXPORT_ERR.txt</source-file-path> </source-file> <destination-file id='2'> <destination-file-path>L:\Enterprise Reports\Input Files\ +ipCNAM1D001Error.txt</destination-file-path> </destination-file> </report> </reports>
And my code goes as
use Win32::OLE qw(in with); #my $xml_file = 'file.xml'; my $DOM_document = Win32::OLE->new('MSXML2.DOMDocument') or die "new() + failed"; $DOM_document->{async} = "False"; $DOM_document->{validateOnParse} = "True"; my $boolean_Load = $DOM_document->Load("file.xml"); if (!$boolean_Load) { die "topten.xml did not load"; } my $Reports = $DOM_document->DocumentElement(); my $Report = $Reports->childNodes(); foreach my $Event (in $Report) # make sure you include the 'in' { my $temp =$Event->Attributes->getNamedItem("report-name")->{text}; print $temp; }
I want to get the report names (POSM1M029,CNAM1D001 etc. Please tell me where I am wrong. Thanks for your help.

In reply to Extracting information from XML file by Nesh

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.