in reply to Match on line, read backwards to opening xml tag then forward to closing tag
Please let me know if this works for youuse strict; use warnings; { my ($input_file) = @ARGV; open XML, $input_file or die; my $xml_data; ##Read the XML into xml_data while (my $line = <XML>){ $xml_data .= $line; } ##Parse xml_data while ($xml_data =~ /<Dataentry>(.*?)<\/Dataentry>/s){ ##Keep xml block to print if needed my $xml_block_to_print = $1; my $xml_block_to_parse = $xml_block_to_print; $xml_data = $'; ##Parse the xml block, and if we have a match, print! while ($xml_block_to_parse =~ /<Data>(.*?)<\/Data>/){ my $data = $1; $xml_block_to_parse = $'; if ($data eq 'bbbbbb'){ print "$xml_block_to_print\n"; last; } } } }
|
|---|