'Python adding opening and closing tags to word documents

I'm currently trying to figure out a way to input opening and closing xml tags to certain lines inside word documents I have. Example word document I have that needs editing.

<title>Hello this is the Title</title>
<para>This is the para text inside the title. Testing… 1…2….3.</para>
<title>This is another Title example.</title>
<para>This is another para example of that title example.</para>



import docx

xmlWordtag = docx.Document('WordTagEx.docx')

for line in xmlWordtag.paragraphs :

So far I have this written which reads thru each line in my word document. Now how would I go about to editing this document and adding the tags to the paragraph text and the titles.

I am pretty new to coding so I apologize in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source