in reply to Re: XML::Twig help please
in thread XML::Twig help please
The following code reads the <appDeploymentFile> URL's but only for the first section of <application> IOW, I get all the URL's for the section <application name ="hk"> but none for the <application name ="intl">. Here's my code now:<authenticationReports> <generatedTime>Tue Sep 29 07:07:34 PDT 2009</generatedTime> <appDeploymentFile name="app-deployment.properties.hklcp.trading"> <application name="hk"> <urlInfo> <url>a/b/hk/accts_subscription</url> <otherPrereq>HKPwdPreReq</otherPrereq> </urlInfo> <urlInfo> <url>a/b/hk/accts_forms</url> <otherPrereq>HKPwdPreReq</otherPrereq> </urlInfo> <urlInfo> <url>a/b/hk/custtradingpage</url> <otherPrereq>BasicPrereq</otherPrereq> </urlInfo> <urlInfo> <url>a/b/hk/accts_userinfo</url> <otherPrereq>HKPwdPreReq</otherPrereq> </urlInfo> <urlInfo> <url>a/b/hk/headermain</url> </urlInfo> <urlInfo> <url>a/b/hk/custservicepage</url> </urlInfo> <urlInfo> <url>a/b/hk/accts_transfermoney</url> <otherPrereq>HKPwdPreReq</otherPrereq> </urlInfo> <urlInfo> <url>a/b/hk/userprereq</url> </urlInfo> <urlInfo> <url>a/b/hk/indices_us</url> </urlInfo> <urlInfo> <url>a/b/hk/homeloggedmessage</url> </urlInfo> <urlInfo> <url>a/b/hk/lead</url> </urlInfo> <urlInfo> <url>a/b/hk/orderviewmin</url> </urlInfo> <urlInfo> <url>a/b/hk/accts_changelogin</url> <otherPrereq>SessionPreReq</otherPrereq> </urlInfo> </application> <application name="intl"> <urlInfo> <url>a/b/intl/quotesandresearch</url> </urlInfo> <urlInfo> <url>a/b/intl/intltablesubnavviewcomponent</url> </urlInfo> <urlInfo> <url>a/b/intl/intltablemetaviewcomponent</url> </urlInfo> <urlInfo> <url>a/b/intl/disclaimer</url> </urlInfo> <urlInfo> <url>a/b/intl/headermain</url> </urlInfo> <urlInfo> <url>a/b/intl/indices_us</url> </urlInfo> <urlInfo> <url>a/b/intl/lead</url> </urlInfo> <urlInfo> <url>a/b/intl/selectlanguage</url> </urlInfo> <urlInfo> <url>a/b/intl/get-screen</url> <otherPrereq>BasicPrereq</otherPrereq> </urlInfo> <urlInfo> <url>a/b/intl/page_f</url> </urlInfo> <urlInfo> <url>a/b/intl/basicprereq</url> </urlInfo> <urlInfo> <url>a/b/intl/page</url> <otherPrereq>BasicPrereq</otherPrereq> </urlInfo> </application> </appDeploymentFile> </authenticationReports>
How can I 1. Get all URL's in any given <appDeploymentFile> section and 2. append the <application> NAME value to the end of the $NAME (value) of the Hash? I can then parse it later. I played with various child/next_child, etc parameters, and just ain't grokking it yet. Thanks for the input. First time, I've tried to use XML::Twig before... XML::Simple had always met my needs.sub AFXMLtoEM { print "Slurping $AFXML...."; my $TWIG = new XML::Twig ( twig_handlers => {'appDeploymentFile' = +> \&parseURL} ); #my $TWIG = new XML::Twig ( twig_handlers => {'appDeploymentFile/a +pplication' => \&parseURL} ); $TWIG -> parsefile ($AFXML) or die "Can't open $AFXML\n" ; $TWIG->flush; # Now we want to change every value from the XML name to an EM ins +tance identifier #print Dumper(\%AFURLS); exit 1; while ((my $K, my $ITEM) = each %AFURLS) { my ($G1,$G2,$APP,$INST) = split /\./,$ITEM,4; unless ($APP eq "") { $ITEM = "prd:" . $APP . ":web:" . $INST; } #Cheesy kludge - fiox when Durai confirms $AFURLS{$K} = $ITEM; } print scalar keys %AFURLS, " records slurped in.\n"; } sub parseURL { my ($T, $ADEP) = @_; my $NAME = $ADEP->att('name'); for my $URLI ($ADEP->first_child('application')->children('urlInfo +')) { #for my $URLI ($ADEP->children('urlInfo')) { # leading slash added for matching SM filters $AFURLS{ "/" . $URLI->first_child('url')->text() } = $NAME; } #$ADEP->flush; }
|
|---|