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...


In reply to XML::LibXML help needed... by spstansbury

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.