You could use regex for quick results:
import re
x = """
<?xml version='1.0' encoding='UTF-8'?>
<inno:dom xmlns:inno="http://innodatalabs.com/innodom">
<inno:meta>
<inno:datapoint idref="text-61">Yes</inno:datapoint>
<inno:datapoint idref="text-64">No</inno:datapoint>
<inno:datapoint idref="text-67">Personal Information</inno:datapoint>
<inno:datapoint idref="text-68">Non-Personal Information</inno:datapoint>
</inno:meta>
</inno:dom>
"""
result = re.sub(r">([^<
]+)</", lambda x: ">NA</" if x.group() == ">No</" else ">Yes</", x)
print(result)
But as @mzjn pointed out, in general it's not a great idea to change XML files using regex.
Please see ElementTree and how to modify XML files.
Example:
import xml.etree.ElementTree as ET
if __name__ == "__main__":
namespace_uri = "http://innodatalabs.com/innodom"
ET.register_namespace('inno', namespace_uri)
tree = ET.parse('test.xml')
root = tree.getroot()
for child in root.iter("{{{0}}}datapoint".format(namespace_uri)):
text = child.text
if text == "No":
child.text = "NA"
else:
child.text = "Yes"
tree.write("output.xml")
where test.xml
is your example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…