I would strongly recommend against floundering about in OOo's very
complex XML files - it is trivially easy to render a document unusable.
I do it all the time and have never had a problem. I don't generate the
documents from scratch; I generate a template that contains everything
that don't need to dynamically generate. Then I use one of two methods
to to update the content.xml:
1. In the simplest cases, I only need to change a single data field. I
replace the literal data in the content.xml file with:
<replace field="variable_name"/>
Then, using a DOM implementation, I can use getElementsByTagName()
to get all of the replace tags and send the variable name to a
distpach that generates the text used to replace the tag.
2. For collections of data (spreadsheet cells, table cells/rows, etc,
I leave one piece of sample data in place. I then clone the DOM
element that I can use as a template and delete the origional.
Entering the data is then a simple matter of cloning the template
element, updating the information that it contains, and adding
it to the childNodes of the parent. Since tags all come from
the file that O
rg/LibreOffice generated, the resulting markup
will be valid.
Once the content.xml file has been updated, I simply run jar as a
subprocess to update the content.xml file in the ods/odt file.