How can I edit an underlying structure of a Writer document?

I have a messy Writer document, and I would like to clean it up. Using the WYSIWYG editor is impractical because I do not see the exact structure and all properties, so I need to check direct formatting, paragraph styles and other styles, lists and tables all separately, and it is easy to overlook something.

If it was a HTML document, I would use Inspect Element in a web browser, and I could see and edit the structure to clean it up. Is something similar possible in Libreoffice Writer? Or is there a different program which allows me to edit the structure? In an extreme case, I could try to edit the XML in a text editor, but the format is complex, so all my attempts to edit the XML so far have resulted in incorrect files. Therefore, I would like something which keeps the document structurally correct while editing.

Don’t try to fiddle the underlying XML. As you noticed it is a very complex encoding. The odds are very high you mess even more your document.

Is it an .odt or some other alien format? With which LO version was it last edited? You can tell by looking at the XML (without trying to patch it) at the beginning. The second element is a <office:meta> block with a <meta:generator> sub-block. This will tell you the version of the last edit.

“Recent” versions introduced a feature to improve document version comparisons. This is implemented as a kind of direct-format similar to an anonymous character style. And it clutters a lot the XML. Removing it would allow you to have a better understanding of your structure but you may damage the document doing so.

It’s a DOCX file from Word which was saved as ODT when I edited it in Writer 25.8.

Then forget about trying to “fix” the XML. You add (multiply?) potential issues in Writer itself with the approximations of conversion from DOCX (there is no one-to-one mapping between DOCX and ODF; some formatting directives must be “interpreted” with surrogates).

The best you can do is customise built-in styles in a blank document, design “missing” styles and paste as unformatted text. What is left is to transfer manually footnotes and apply styles over the whole text.

1 Like

There is a feature called Spotlight which was introduced in version 7.6; this may be of some use to you.

Spotlight is very useful to me when I work with styles. But it does not suffice here because it does not show direct formatting, lists and table settings, which are the things which are messy in the document.