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&" > <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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |