Get/update XML structure with PyUno-Extension

Hi everyone,

I am developing a LibreOffice extension with PyUno for LibreOffice writer. The extension should replace single words in the text with other words (without changing the formatting) and black out areas.

At the moment I iterate within the extension laboriously over the single paragraphs and text sections to pick out the single words. The words are then sent to a web service. The web service analyzes the words and returns the result to the extension. Then the extension replaces the words in the document.

Code already exists in the web service that can extract and replace words from an ODT file. Therefore, it would be good if the extension can use this code.

I need support with the following questions:
How do I get the current processing state of the file (preferably the XML structure) via the extension? It is imperative that unsaved changes are also taken into account.

How do I replace the complete content of the opened document (preferably replacement of the XML structure)?

Is there a possibility to get the XML structure of a selected area?

I have already succeeded in extracting the saved XML via the extension. Unfortunately, not saved changes are missing here. One could also save the results of web service in a file and then reopen it with LibreOffice. But it would be more user friendly if this is done in the same window.

Does anyone have any ideas how I can implement my plan?

Thanks a lot and best regards


When the document is imported into the document model, there’s no XML there, so you can’t use the XML unless you do the export. I also doubt there’s a code to get an XML of a part of document; even when you create a transferrable (as in copy/paste), the native object there in the clipboard is a document model, not an XML.

Thanks for your answer. I could write the current state of the document to a temporary file using “storeToURL” and send it to the web service. The web service then sends me back a modified file. How do I get the contents of the modified file into the document opened by the user without having to save or close it?