Øystein,
Hi. By "normalizing" line endings, do you mean it puts each tag on a separate line? If Microsoft's XML Notepad is doing that, then it is a valuable tool. I'll give it a try.
What you did, I think Jeeped is doing too. When you put the document.xml tags on separate lines using NotePad++ and then rezip all the files, Word is still able to read it and now tells you exactly which line to go to find the XML
error. I just checked and even Word 2013 does this.
I was first clued into this technique by Daniel "3ICE" Berezvai posts here: http://bit.ly/1s4TPsT. Below are his steps to put the document.xml XML tage on separate lines
using NotePad++. Please note in step 3, *it is vital that you the radio button in the Replace Window in the "Search Mode" Section in the lower left, from "Normal" to "Extended" or it won't work! In Normal mode Notepad++,the new line (\n) and return (\r) character combinations will be added as plain text not as the hidden formatting characters they need to be.*You can even see these hidden formatting characters by choosing the Show Symbol submenu on the View menu and click on "Show all characters".
:
- "Change your file extension from docx to zip *
- Extract word/document.xml * [The zip structure of corrupt DOCX files with the Unspecified error type are usually not damaged, but if you can't unzip the file, try repairing the zip file first. For that I think the best is the fixfix (-FF) command of the free InfoZip's zip.exe. Once you have a repaired zip, I find 7zip is the best at extracting repaired zip files.]
- Using a Programmer's Notepad (I prefer Notepad++) replace >< with >\r\n< in
Extended mode to make the XML more readable, putting each tag on its own line. (The expression \r\n stands for new line in windows.) You can use regexp mode or multi-line replace in other text editors,
or copy a newline/hidden paragraph symbol and paste it in the replace box. (Which works even in Word.) [Notepad++ even has a halfway decent multiline replace tool in the ToolBucket plugin which can easily be using the Plugin Manager on the Plugin menu.]
- Import the modified word/document.xml back into the archive [and rezip if you have unzipped to extract theword/document.xml file. It is imperative to rezip starting for the root of the file, where the[Content_Types].xml hangs out. Don't go up one level so that you are zipping one folder which has the _rels, customXml, docProps and word folders plus the*[Content_Types].xml (if your file has all those folders otherwise work with what you have), otherwise Word won't recognize it.*]*
- Rename it back from zip to docx *
- Attempt to open the document
- Note that this time the error message will be more useful, for example it will tell you that the error is at: line 13540, as opposed to line 2 column 0.
- Go to the line specified (was 13540 for me) and remove it. And the tags around it too, if necessary. Make sure you keep the XML well-formatted! (You can attempt to fix the erroneous line instead of removing it, but usually the indicated line is as useless
as the other lines around it, so removal will not result in any loss of data. See the note** below for why this is.)
- Import document.xml and rename zip/docx as usual. *
- Repeat steps 6-9 until your document is recovered. (Took me 5 repeats, as more errors arose at lines 15870, 13595, 13222 and 10835.*** (Not sure why it found errors in reverse order, but it did.)
* These steps are unnecessary if you use Total Commander (or other advanced file managers). It can look inside docx files as if they were folders because it automatically recognizes
them as compressed archives. It also lets you edit files easier, just press F4. And it even detects file changes and asks if it should reimport your edited files into the archive upon closing the editor.
** Note: To me it seems that none of the errors were real. While the source code was extremely bloated and wasteful, every indicated error was a line with completely well formed XML.
(Around it was good XML too.) For pages and pages, almost every line repeated the same statement:"