import xml.dom.minidom import sys import os def find_node(doc_node, tag_name, attribute_name, attribute_value): elements = doc_node.getElementsByTagName(tag_name) for element in elements: if element.hasAttribute(attribute_name): if element.getAttribute(attribute_name) == attribute_value: return element def save_xml_file(doc_node, output_file): fp = file(output_file, "w") fp.write(doc.toxml()) fp.close() def update_counter(doc, text_node, replacement_text): text_node.replaceChild(doc.createTextNode(replacement_text), text_node.firstChild) if __name__ == "__main__": doc = xml.dom.minidom.parse(sys.argv[1]) replacement_text = sys.argv[2] output_file = sys.argv[3] text_node = find_node(doc, "tspan", "id", "text-to-translate") update_counter(doc, text_node, replacement_text) save_xml_file(doc, output_file) os.system("convert %s %s.translated.png" %(output_file,output_file)); os.system("rm %s" %(output_file));