Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: need to parse nested XML

by tmharish (Friar)
on Mar 04, 2013 at 04:28 UTC ( #1021576=note: print w/ replies, xml ) Need Help??


in reply to need to parse nested XML

You can do it with XML::Smart like so:

use strict ; use XML::Smart ; my $xml = join( '', <DATA> ) ; my $xml_obj = XML::Smart->new( $xml ); $xml_obj = $xml_obj->{ 'press-release' }{ 'PromoModuleOne' }{ 'RightCo +loumn' }{ Tabs } ; foreach my $tab ( @{ $xml_obj } ) { print $tab->{ TabName }->content() ." \n" ; foreach my $links ( @{ $tab->{ Links } } ) { print $links->{ AssetTitle } . "\n" ; print $links->{ AssetSource } . "\n" ; print $links->{ AssetLink } . "\n" ; print "#" x 50 ; print "\n"; } print "*" x 50 ; print "\n"; } __DATA__ <press-release> <PromoModuleOne> <ModuleBackgroundImage>images/section_bg.png</ModuleBackground +Image> <ColorCode>BLUE</ColorCode> <LeftColoumn> <PromoImage>XXXXXX</PromoImage> <HeadingImage>XXXXXX</HeadingImage> <PromoLink>XXXXXX</PromoLink> <PromoText>XXXXXX</PromoText> </LeftColoumn> <RightColoumn> <Tabs> <TabName>XXXX</TabName> <Links> <AssetTitle>asd</AssetTitle> <AssetSource>asdasd</AssetSource> <AssetLink>asdsadasd</AssetLink> </Links> <Links> <AssetTitle>sadas</AssetTitle> <AssetSource>asdsa</AssetSource> <AssetLink>dasdas</AssetLink> </Links> </Tabs> <Tabs> <TabName>XXXX</TabName> <Links> <AssetTitle>dsfsdfds</AssetTitle> <AssetSource>dsfds</AssetSource> <AssetLink>sdfdsfsdf</AssetLink> </Links> </Tabs> </RightColoumn> </PromoModuleOne> </press-release>

OUTPUT:

XXXX 
asd
asdasd
asdsadasd
##################################################
sadas
asdsa
dasdas
##################################################
**************************************************
XXXX 
dsfsdfds
dsfds
sdfdsfsdf
##################################################
**************************************************


Comment on Re: need to parse nested XML
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021576]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-07-31 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (245 votes), past polls