Object: Match strings in file to string in XML. Replace Match with comments
cat File.txt
RHO_BID_RT
RHO_ASK_RT
XML FILE CONTENTS
<field name="RHO_BID_RT" type="float" id="0x01D3" sequence="1"/>
<field name="RHO_ASK_RT" type="float" id="0x01D4" sequence="1"/>
INTENDED RESULTS in XML CONTENTS
<!-- Removed RHO_BID_RT-->
<!-- Removed RHO_ASK_RT-->
CODE
import re
word_file = 'File.txt'
xml_file = '../file.xml'
with open(word_file) as words:
regex = r'<[^>]+ *field name="({})"[^>]+>'.format(
'|'.join(word.rstrip() for word in words)
)
with open(xml_file) as xml:
for line in xml:
line = re.sub(regex, r'<!!-- REMOVED \1 -->', line.rstrip())
print(line)