Here is a way to extract all the necessary info from your XML using
XML::LibXML and simple xpath queries. You will probably want to save the results to a data structure (an array of hashes should work) rather than printing them out like I do, but printing them out first allows you to see if it is working correctly.
See XML::LibXML::Node and XML::LibXML::Element for more details.
use XML::LibXML;
my $doc = XML::LibXML->load_xml(location => '/path/to/file.xml');
my @envdetails = $doc->findnodes('//ENVDETAILS');
for my $envdetail (@envdetails) {
my $id = $envdetail->getAttribute('id');
print "id: $id\n";
my $dmgrhost = $envdetail->findvalue('DMGRHOST');
print "DMGRHOST: $dmgrhost\n";
my @nodes = $envdetail->findnodes('NODE');
for my $node (@nodes) {
my $nodeid = $node->getAttribute('nodeid');
print "nodeid: $nodeid\n";
my $nodehost = $node->findvalue('NODEHOST');
print "NODEHOST: $nodehost\n";
my @jvms = $node->findnodes('JVM');
for my $jvm (@jvms) {
my $jvmtype = $jvm->getAttribute('jvmtype');
if ($jvmtype eq 'api') {
my @jvmnames = $jvm->findnodes('JVMNAME');
for my $jvmname (@jvmnames) {
my $name = $jvmname->textContent;
print "JVMNAME: $name\n";
}
}
}
}
}
# OUTPUT
id: abc
DMGRHOST: a.b.c.d
nodeid: 1
NODEHOST: v.x.y.z
JVMNAME: abc_api1.1
JVMNAME: abc_api1.2