So I have several XML files that have persons with unique IDs and they each have a favorite food (a person can be in several xml files):
There are cases where the person with id=300 might have the food right in the beginning of the tag.
<person id="299">
<food>
<type> Hot Dog </type>
</food>
</person>
<person id="300">
<food>
<type> Burger</type>
</food>
</person>
Or there might be other tags before the food tag
<person id="300">
<year>
<birth> 1990 </birth>
<marriage> 2020 </marriage>
</year>
<food>
<type> Vegan </type>
</food>
</person>
I need to use a single Perl RegEx functions to remove the food tags ONLY of the persons whose ID is 300, independently if it is at the beginning, middle, or end of the person tag
I know if it was for the whole person tag I could use something like :
$fileContents =~ s/<person id=\"300\"[^<]+<\/person>//g;
But I must leave the person tag intact, I must only remove the food tag inside the person tag, but I can't remove all the food tags because I need to leave it for people with other ID's.
Could you help me please?? I been struggling a lot with this D: