Hello monks, I have an XML file that I wish to parse and store information from some of the branches in arrays. I have tried several different approaches and none seem to do what I need. It is the url tag that I wish to store into different arrays.

Thanking anyone in advance for any insight

use LWP::Simple; use XML::Simple; use Data::Dumper; use strict; use warnings; my $parser = XMLin("c:\\temp\\data.xml"); print Dumper($parser); print $parser->{HttpSiteAddress} . "\n"; print $parser->{SiteAssets}->{asset}->{url}, "\n"; print $parser->{FragmentAssets}->{asset}->{url}->[1];

Produces the following output + error:

$VAR1 = { 'PublishInfo' => { 'nodeUrl' => [ { 'nodeId' => '27', 'url' => 'index.htm' }, { 'nodeId' => '256', 'url' => 'foia/index.htm' }, { 'nodeId' => '259', 'url' => 'foia/2006/index.ht +m' } ] }, 'siteStudioVersion' => '7.7.0.1', 'SiteAssets' => { 'asset' => { 'url' => '/ucm/groups/public/@web +sitestructure/documents/file/pghdr_left.jpg', 'dDocName' => 'pgHdr_left' } }, 'getPageUrl' => '/ucm/idcplg?IdcService=SS_GET_PAGE&', 'siteStudioBuild' => '9.0.0.506', 'FragmentAssets' => { 'asset' => [ { 'url' => '/ucm/fragments/we +b_header/css/nav_ie6fix.css' }, { 'url' => '/ucm/fragments/cs +s4footer/img/promotions/transparency.png' }, { 'url' => '/ucm/fragments/cs +s4footer/img/bg-box-menu.gif' } ] }, 'format' => '1.1', 'HttpRelativeWebRoot' => '/ucm/', 'siteId' => 'CFTC', 'DeclaredAssets' => {}, 'HttpSiteAddress' => 'http://dc2kd11.cftc.gov:7070/' };
http://dc2kd11.cftc.gov:7070/ /ucm/groups/public/@websitestructure/documents/file/pghdr_left.jpg Not a HASH reference at C:\apache\apache2.2\cache_proxy\cgi-bin\test3. +pl line 12.

The input file looks like this:

<?xml version="1.0" encoding="UTF-8"?> <SiteStudioManifest format="1.1" siteStudioVersion="7.7.0.1" siteStudioBuild="9.0.0.506" siteId="CFTC" HttpSiteAddress="http://dc2kd11.cftc.gov:7070/" HttpRelativeWebRoot="/ucm/" getPageUrl="/ucm/idcplg?IdcService=SS_GET_PAGE&amp;" > <FragmentAssets> <asset url="/ucm/fragments/web_header/css/nav_ie6fix.css"/> <asset url="/ucm/fragments/css4footer/img/promotions/transpare +ncy.png"/> <asset url="/ucm/fragments/css4footer/img/bg-box-menu.gif"/> </FragmentAssets> <PublishInfo> <nodeUrl nodeId="27" url="index.htm"/> <nodeUrl nodeId="256" url="foia/index.htm"/> <nodeUrl nodeId="259" url="foia/2006/index.htm"/> </PublishInfo> <DeclaredAssets> </DeclaredAssets> <SiteAssets> <asset dDocName="pgHdr_left" url="/ucm/groups/public/@websites +tructure/documents/file/pghdr_left.jpg"/> </SiteAssets> </SiteStudioManifest>

In reply to Problem parsing XML into arrays using XML::Simple by tevolo

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.