I have an XML file in a string variable ($data
), and a hash containing all the tag names and their contents (%field_list
).
The tag names are to be checked so that if they are enumerated fields, their contents should be replaced with strings.
Does anybody know if it is possible to do this with search and replace? I am not having much luck at the moment.
foreach my $field (sort keys %field_list)
{
my $value = $field_list{$field};
# will return a non-empty string if field is enumerated and value is valid
my $enum_string = &convert_enumeration_to_string($field, $value);
if ($enum_string ne "")
{
#syntax error
$data =~ s/<($field)>($value)</($field)>/<($field)>($enum_string)</($field)>/g;
}
}
Does anybody know whether there is anything I can do, or do I need a completely different approach?