[Solved] How save .xml changes in .odt file

Discuss the word processor
Post Reply
catbill
Posts: 81
Joined: Sun Oct 08, 2017 6:51 pm

[Solved] How save .xml changes in .odt file

Post by catbill »

To solve a problem on another post, I extracted the contents of a document and made some changes to content.xml. Now I want the document to use the revised version of content.xml. But how do I do that?

Someone said to rezip the files (in the folder of extracted files). Rezipping the file creates a .zip file. But when I try to save the .zip file as an .odt file, Windows warns that it could be unstable.

I am sure that this is not hard to do but I have little experience with xml and a web search couldn’t help me (probably because I don't know the appropriate search terms).

The people on the other post have been helpful but they have not been able to respond for a few days. I am hoping to be able to do this as soon as possible so thought that maybe someone else could give a quick answer.

FYI, this is the other post: viewtopic.php?f=7&t=91240
Last edited by Hagar Delest on Sun Dec 10, 2017 11:42 pm, edited 1 time in total.
Reason: tagged [Solved].
LibreOffice 6.2.6.2
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How save .xml changes in .odt file

Post by FJCC »

After editing the content.xml file zip it back with all the original files and folders. Change the extension back to .odt. Windows will bring up a warning about this possibly making the file unusable. Ignore that. Open the odt file with OpenOffice and see if it your changes to the content.xml achieved what you want.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
catbill
Posts: 81
Joined: Sun Oct 08, 2017 6:51 pm

Re: How save .xml changes in .odt file

Post by catbill »

Thank you, FJCC, for the fast reply!

I just tried that but OO said that the file is corrupt and cannot be repaired. In addition to any problems from renaming the file, this could also mean that my earlier manipulation of the file went awry.

Is it common that just renaming the file leads to instability?

It seems that there must be another way to do this that does not lead to a warning of file instability. Any more suggestions?
LibreOffice 6.2.6.2
Bill
Volunteer
Posts: 8932
Joined: Sat Nov 24, 2007 6:48 am

Re: How save .xml changes in .odt file

Post by Bill »

It's simple using 7-zip. Download and install 7-zip. Right-click the odt file and select 7-zip > Open Archive. Drag the content.xml file from the 7-zip window to the Desktop. Edit and save the content.xml file on the Desktop. Drag the edited content.xml file back to the 7-zip window. Close 7-zip.
AOO 4.1.14 on Ubuntu MATE 22.04
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: How save .xml changes in .odt file

Post by FJCC »

Renaming the file will not cause any real problems. That warning from Windows is an exaggeration. The only thing that may change when you change the file extension is the default program for opening the file. The content of the file is not affected in any way.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
musikai
Volunteer
Posts: 294
Joined: Wed Nov 11, 2015 12:19 am

Re: How save .xml changes in .odt file

Post by musikai »

Hi,
Often people are making an error when zipping the files. Don't select the folder where the files are located in. Select all files and folders in the main folder and zip these. Then rename to .odt
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: How save .xml changes in .odt file

Post by John_Ha »

Bill wrote:It's simple using 7-zip ...
+1 You can drag a file out of 7-Zip and drag a file into 7-Zip. It is very easy.
Attachments
test.odt file opened with 7-Zip.  Drag a file into or out of the window
test.odt file opened with 7-Zip. Drag a file into or out of the window
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Bill
Volunteer
Posts: 8932
Joined: Sat Nov 24, 2007 6:48 am

Re: How save .xml changes in .odt file

Post by Bill »

catbill wrote:To solve a problem on another post, I extracted the contents of a document and made some changes to content.xml. Now I want the document to use the revised version of content.xml. But how do I do that?

Someone said to rezip the files (in the folder of extracted files). Rezipping the file creates a .zip file. But when I try to save the .zip file as an .odt file, Windows warns that it could be unstable.
You don't need to extract all the files and then rezip them after editing content.xml. If you use the Windows Compressed Folder feature instead of an archive manager like 7-Zip, you just change the .odt file name extension to .zip, then double-click the renamed file. It will open in File Explorer. Drag the content.xml file from the File Explorer window to the Desktop to extract the content.xml file. You can then edit the content.xml file on the Desktop. When finished, drag the edited content.xml file from the Desktop back to the File Explorer window. Windows will display a message with options to "Copy and Replace" or "Don't copy". Select "Copy and Replace". That will rezip the file with the edited content.xml file. Now you can change the file name extension back to .odt and open the edited file with OpenOffice.

The process is similar to the process when using 7-Zip, but with 7-Zip you don't have to rename the file.
AOO 4.1.14 on Ubuntu MATE 22.04
catbill
Posts: 81
Joined: Sun Oct 08, 2017 6:51 pm

Re: How save .xml changes in .odt file

Post by catbill »

Thank you for the simple solution.
LibreOffice 6.2.6.2
mdkb
Posts: 6
Joined: Thu May 10, 2018 1:54 pm

Re: [Solved] How save .xml changes in .odt file

Post by mdkb »

none of these methods work for me, it always comes back corrupt. the only way I have worked it so far is to edit it while it stays in the container, without extracting the file and using 7-zip to open the container then right click and edit to access the xml file and save it back. if I extract and then put it all back it refuses to open after.
Open Office 4.1.5 on Windows 10 64 bit.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: [Solved] How save .xml changes in .odt file

Post by John_Ha »

mdkb wrote:none of these methods work for me
1. rename fred.odt to fred.zip
2. double click fred.zip. It opens like a folder. Now just drag in or out and/or copy/paste.
3. rename fred.zip to fred.odt

NOTE: Editing content.xml is never a recommended course of action (except in an emergency like a corrupted file) and is always likely to cause problems unless you fully understand XML, AOO's use of XML and exactly what you are doing.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
RoryOF
Moderator
Posts: 34612
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] How save .xml changes in .odt file

Post by RoryOF »

In addition to John_Ha's warning about editing OO's content.xml, I recommend passing it through an XML verifier before placing it back in the ODF file. When I have to edit .xml files (to repair them) I use XMLCopyEditor, and use its /XML /Check Well-formedness option to verify that the file's syntax is correct.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
mdkb
Posts: 6
Joined: Thu May 10, 2018 1:54 pm

Re: [Solved] How save .xml changes in .odt file

Post by mdkb »

1. rename fred.odt to fred.zip
2. double click fred.zip. It opens like a folder. Now just drag in or out and/or copy/paste.
3. rename fred.zip to fred.odt
yea exactly what I have done a number of times and different ways to try to figure out why it doesnt work, and I dont change anything in the files it still does it so it is a clean unpack and repack. but the odt wont work after.

I am on windows 10 build 1709, 7-zip is 1604 64 bit. I have tried with the windows compress but no different.

I can only think something is happening on the windows side of things but no idea what.

As I shared in another post, I can edit the xml if I dont unpack the odt, but when I work with it inside the compressed folder by using 7-zip I run into another problem with updating the changes I make later in the document, I have to read the manual to see if it is in there apparently. Planning to look today at that.
Open Office 4.1.5 on Windows 10 64 bit.
mdkb
Posts: 6
Joined: Thu May 10, 2018 1:54 pm

Re: [Solved] How save .xml changes in .odt file

Post by mdkb »

ok I have solved my issue.

After unpacking the .odt, I was then zipping up the main folder containing all the files, what I needed to do was zip up the files themselves, and not the parent folder.
probably obvious to some, but I assumed the parent container was what was being unpacked and needed to be packed up again.
Open Office 4.1.5 on Windows 10 64 bit.
Post Reply