title: How to open/save docx file to be aditted as xml and save the result as docx after editting using python
body: <p>I have a <code>docx</code> file in which I need to edit its paragraphs (the paragraphs might contain equations). I tried to do these jobs using <code>python-docx</code> but it was not successful since editing the text of each paragraph and replacing it with the edited new paragraph needs to call <code>p.add_paragraphs(editText(paragraph.text))</code> which ignores and omits any mathematical equation.</p>
  
  <p>By searching for a method to gain this goal I found that this job is possible through XML codes by finding <code>&lt;w:t&gt;</code> tags and editing their content like this:</p>
  
  <pre><code>tree= ET.parse(filename)
  root=tree.getroot()
  
  for par in root.findall('w:p'):
     if par.find('w:r'):
     myText= par.find('w:r').find('w:t')
     myText.text= editText(myText.text)
  </code></pre>
  
  <p>Then I must save the result as docx.
  My quation is: what the format of filename is? should it be a document.xml file? If so, how can I reach that from my original document.docx file? and one more question is that how can I save the result as a .docx file again? </p>
  
  <p>For saving docx as xml, I have given a try to save it by <code>document.save('Document2.xml'</code>). But the content of the result was not correct.</p>
  
  <p>Would you give me some advice how to do them?</p>