I have an xml file - here is a snippet..
{0328cb65-b564-495a-b17e-e49e04864ab7}
You'll have to query the whole node instead of only its contents:
code = root.xpath('//gmd_identifier/gmd_RS_Identifier/gmd_code/gco_CharacterString')
Then, if it matched, just replace its text and save back to the XML file:
if code:
# Replaces <gco_CharacterString> text
code[0].text = '{0328cb65-b564-495a-b17e-e49e04864ab7}'
# Save back to the XML file
etree.ElementTree(root).write('D:\test.xml', pretty_print=True)
That's all! :)