sbafna has asked for the wisdom of the Perl Monks concerning the following question:
I have the below complex yet small XML snippet saved in a file, with multiple entries of ENVDETAILS.
<OUTMOST> <MYENVDETAILS> <ENVDETAILS id="abc" > <DMGRHOST>a.b.c.d</DMGRHOST> <CELL>XYZ</CELL> <NODE nodeid="1" > <NODEHOST>v.x.y.z</NODEHOST> <IHSNODE>v_ihsnode</IHSNODE> <IHSJVM ihsjvmtype="log_ihs" > <IHSJVMNAME>abc_logihs1</IHSJV +MNAME> </IHSJVM> <IHSJVM ihsjvmtype="appihs" > <IHSJVMNAME>abc_appihs1</IHSJV +MNAME> </IHSJVM> <JVM jvmtype="nodeagent" > <JVMNAME>nodeagent</JVMNAME> </JVM> <JVM jvmtype="api" > <JVMNAME>abc_api1.1</JVMNAME> <JVMNAME>abc_api1.2</JVMNAME> </JVM> </NODE> </ENVDETAILS> </MYENVDETAILS> </OUTMOST>
Few things we must know:
a). nodeid is not unique.
b). ENVDETAILS id is unique.
I wanted to achieve/perform the following things:1). Display all the ENVDETAILS ids: [output should have all ids: abc]
2). Display all the jvms corresponding to ENVDETAILS ids & after checking the jvm type: [input: (id=abc)(jvmtype=api) output should have all jvms of type 'api' from ENV id 'abc' i.e.: abc_api1.1, abc_api1.2 ]
3). Display the NODEHOST of JVMNAME is entered as input: [input: jvm=abc_logihs1output should be NODEHOST of jvm 'abc_logihs1' i.e.: v.x.y.z]
4). Display all the jvmtype present on the NODEHOST entered as a input: [input: NODEHOST=v.x.y.z output should be: log_ihs, appihs, nodeagent, api]
5). Display the CELL of NODEHOST is entered as a input: [input: NODEHOST=v.x.y.z output should be: XYZ ]
6). Display the nodeid when NODEHOST is entered as a input: [input: NODEHOST=v.x.y.z output should be: 1 ]
7). Display the DMGR when JVMNAME is entered as input: [input: jvm=abc_api1.1output should be : a.b.c.d ]
8). Display the ENVDETAILS when JVMNAME is entered as input: [input: jvm=abc_api1.1output should be : abc ]
Please help. I am using XML::Smart to achieve few things, however I am learning perl.I have only written code for 1st point.
use XML::Smart; use strict; use warnings; $ENVFILE="/appl/TOPOLOGY.xml"; my $ENVxml = XML::Smart->new($ENVFILE) || die ("Could not find details + file."); my $env = $ARGV[0]; if ( $ARGV[0] eq "fetch" ) { my @envname=$ENVxml->{OUTMOST}->{MYENVDETAILS}->{ENVDETAILS}(' +[@]','id'); foreach my $i (@envname) { print "$i\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing & retrieving from an XML file
by marto (Cardinal) on Nov 06, 2017 at 17:39 UTC | |
by sbafna (Novice) on Nov 07, 2017 at 08:06 UTC | |
|
Re: parsing & retrieving from an XML file
by Discipulus (Canon) on Nov 06, 2017 at 19:50 UTC | |
by sbafna (Novice) on Nov 07, 2017 at 08:11 UTC | |
|
Re: parsing & retrieving from an XML file
by 1nickt (Canon) on Nov 06, 2017 at 17:22 UTC | |
by sbafna (Novice) on Nov 07, 2017 at 08:09 UTC | |
|
Re: parsing & retrieving from an XML file
by tangent (Parson) on Nov 06, 2017 at 20:57 UTC | |
by sbafna (Novice) on Nov 07, 2017 at 08:12 UTC | |
|
Re: parsing & retrieving from an XML file
by sbafna (Novice) on Nov 08, 2017 at 09:03 UTC |