I am basically a java developer but my client gave me small task in perl. The task is that I will get xml input in that I need to search a element and print it's value(save value in String variable). e.g. in below xml I want to read the value of FileName tag.
<ConnectHome SchemaVersion="1.0.8">
<TransType>0090</TransType>
<Node>
<ExternalFiles>
<FileName>some file name</FileName>
</ExternalFiles>
</Node>
</ConnectHome>
I am using XML:Simple library to parse XML. And I am also able to read the value of element using below code.
$xmlSimple = new XML::Simple(KeepRoot => 1);
$dataXML = $xmlSimple->XMLin("RepeatedElement.xml");
my $fileNameValue = $dataXML->{ConnectHome}->{Node}->{ExternalFiles}->{FileName};
But my client want to search the value using element name as the path may change in xml.
"FileName"
and not the hard coded path.
So my question is how I can get value by name of the element instead of hardcoded path? Is there a method to search element by name? I will pass name of element in string variable.