spstansbury has asked for the wisdom of the Perl Monks concerning the following question:
I'm parsing a XML file where the data section has a number of nodes and then multiple subnodes. When I try to print out the subnodes, I get:
XML::LibXML::Element=SCALAR(0x880714) for all the details.
Here's the code, problem is in the 3rd foreach block...
#!/usr/bin/perl -w use strict; use XML::LibXML; @ARGV == 1 or die("Usage: $0 data file\n"); my $parser = XML::LibXML->new(XML_LIBXML_RECOVER => 2); $parser->recover_silently(1); my $data_file = $ARGV[0]; my $doc = $parser->parse_file( $data_file ); foreach ('root_detail_risklevel_1', 'root_detail_risklevel_2', 'root_d +etail_risklevel_3', 'root_detail_risklevel_4') { my($risk_level) = $_; print $risk_level . "\n"; foreach ($doc->findnodes("//".$_."/data")) { my($risk) = $_->findnodes('./risk'); my($check) = $_->findnodes('./checkname'); my($desc) = $_->findnodes('./description'); my($version) = $_->findnodes('./version'); my($cve) = $_->findnodes('./cve'); my($cce) = $_->findnodes('./cce'); my($summary) = $_->findnodes('./summary'); my($overview) = $_->findnodes('./overview'); my($fix) = $_->findnodes('./fix'); foreach ($_->findnodes('./details')) { my($detail) = $_->findnodes('./vulnDetail'); print $detail . "\n"; } } }
Syntax error in the innermost foreach block?
Help is much appreciated!
Scott...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::LibXML help needed...
by SuicideJunkie (Vicar) on Aug 26, 2009 at 18:12 UTC | |
by spstansbury (Monk) on Aug 26, 2009 at 19:54 UTC | |
|
Re: XML::LibXML help needed...
by ikegami (Patriarch) on Aug 26, 2009 at 18:47 UTC | |
by spstansbury (Monk) on Aug 26, 2009 at 20:00 UTC |