User:Regina/Manipulate Markup of an ODF File

This article describes how to change the source code of an ODF file manually. It is intended for experienced users.

An ODF file can either be a zip-container (e.g. '.odg') or a single XML-file (e.g. '.fodg'). For details about the zip-container see specification part "Packages". For the structure of the XML-files see specification part "OpenDocument Schema". The specification is available from https://docs.oasis-open.org/office/OpenDocument/v1.3/ In both cases you need some knowledge about markup in XML-files. BTW, files in OOXML (e.g. '.pptx') are zip-container too and can be handled the same way.

You need an editor, which is able to manipulate an XML-file based on its nodes. For Windows such editor is "Microsoft XML Notepad" for example. Or you use an editor, which has syntax support for XML. For Windows such tool is "Notepad++" together with the plugin "XML Tools", for example. A simple editor will work too, but you will likely miss some comfort.

Especially when working with a simple editor, it is helpful to save the file in "pretty printing" format. That inserts additional line breaks, so that each element starts in an own line. Pretty printing is disabled as default, because it makes the file a little bit larger. To enable it go to menu Tools > Options > LibreOffice > Advanced > Open Expert Configuration. Type 'pretty' into the search field and click on 'Search'. You should get one hit. Double-click on "PrettyPrinting" to switch it from 'false' to 'true'.

If working with a zip-container, you should not unpack it, but simple enter it. You can e.g. use 7-Zip for that, command 'Open Archive'. 7-Zip gives you the options "Edit" and "View" from the context menu of a file in the archive. Despite of term "View" editing will work there too. You can configure 7-Zip, which applications are used. After you have made changes to a file and saved it, you close the application. Then 7-Zip ask you to update the file in the archive. Agree and close 7-Zip. Now you can open the changed document in LibreOffice and examine, whether your changes have the desired effect. Similar workflow exists for other packers and other operating systems. As always, it is recommended to backup the file before manually changing it.

Errors in xml structure should be detected by the editor. For detecting errors in relation to ODF use the validator https://odfvalidator.org/. You need to select the ODF Version there, 'auto-detect' does not work reliable.