If word docx or doc document file can not be opened because “the name in the end tag of the element must match the element type in the start tag”

This is a sad story with a happy end. I believe a lot of people met the same problem as I have but went to a sad end eventually. Thus, I decide to spend half an hour to write about how I solve this annoying problem to help those people who are desperate to recover their valuable documents.

Sometimes, a very very common operation in the famous Microsoft Office Word software may cause a very serious crash just like the following pic shows. Forgive me some of the information is displayed in Chinese. But you do not have to understand them. They tell only one thing: you are in big trouble now.

Snap2

Fig. 1

People usually search the problem in Google and found some solutions like downloading a microsoft fixing tool which is called MicrosoftFixit.wordopenclosetag.Run.exe. Install and run it to fix the document. Maybe the tool can fix some issues, except mine. I realized that after numerous useless tries (that is why I hate Microsoft’s all kinds of tools and patches). So if you try it once and it doesnot work. Drop it instantly and do not waste time on the tool. Try the method introduced by this article.

Ok. No more nosenses. Let’s begin.

First, backup your crashed document. Even through it cannot be opened, it doesn’t mean the content in it is gone. They are still there. So please be very cautious. Don’t lose temper and delete it. Calm down. Make a copy and put it aside. Then rename the suffix of the document from .docx to .rar.

Snap3

Fig. 2

Then, upzip the .rar to a folder. You will see the actual construction of the mysterious word file. It includes three folders (_rels, docProps, and word) and a file ([Content_Types].xml).

Snap5

Fig. 3

Enter into the word folder.

Snap6

Fig. 4

Open the file document.xml by a text editor. I suggest Notepad++. You can use your favorite editor. But the editor is required to be able to render XML with different colors and highlight the XML structures.

Snap7

Fig. 5

The content of the document.xml is very large and only has two lines. In order to check the problems in the XML, we need to reformat it first. The tool I used for reformating is Eclipse Indigo IDE which is open source and free to download. Create a Java project in Eclipse and create a new file named text.xml. Copy all the content of document.xml into test.xml.

Snap8

Fig. 6

In Eclipse, right click in text.xml. Choose “source” and Click “format”. The XML will be formated into a very friendly style. Copy the formated content back to the document.xml and save document.xml.

Next step is to locate where the error is. Zip all the three folders and files back into a .zip file. Important notice here. The folders and file must be on the first level in the zip file. So the correct way to create the zip file is shown in the following figures.

Snap9

Fig. 7

Select the three folder and the file. Right click on them and click “Add to archive”. A window like Fig. 8 shows up.

Snap11

Fig. 8

Select ZIP and click OK. Rename the suffix of the zip file from .zip back to .docx. Open it with word. An error box (Fig. 9) pops up. Click “details” and you will see the location of the error.

Snap13

Fig. 9

See, it says the error is in row 37507 column 8, So get back to the document.xml in Notepad++. Locate there and observe. Here there is some tricks to quickly find the error. Fold the XML tags around the error locations by clicking the plus symbol on the left margin of Notepad++. Other editors might have similar symbols. If not, download Notepad++ which is also free to use.

Snap17

Fig. 10

Snap18

Fig. 11

After I fold several tags, I found the problem. I found the tag <mc:Fallback> on line 37307 and the tag <m:r> on line 36335 have no end tags (Fig. 10).  So I need to close the two tags. I can use the other complete tags as example and use the same pattern to fill up the missing end tags. In Fig.11 the complete content closing tag <mc:Fallback> is:

<mc:Fallback>
<w:pict />
</mc:Fallback>
</mc:AlternateContent>
</w:r>

However, in Fig. 10 only the first part appears on line 37307:

<mc:Fallback>
<w:pict />

So, we add the missed second part to make it complete.

</mc:Fallback>
</mc:AlternateContent>
</w:r>

Snap19

Fig. 12

It seems good. Let’s see if it works. Save the modified document.xml and repeat the step zipping the folders and file back to word docx.

Snap22

Bingo! It is back! My work is back!!!

Well, let’s conclude the whole process. The most difficult part is finding the missed end tags. Don’t lose your faith. Keep patient. You will find the error eventually. It is even easier than a cross word game. Remember usually the missing tags are all together. It is almost impossible that more than one place is crashed at the same time. Try to find the only place. If one place is fixed, all is fixed. Good luck!

P S. Although this approach depends on nobody and no help which may cost your money, it takes your time, maybe an hour, maybe two hours. To avoid this, be reminded to always backup your important document with version number.

20 thoughts on “If word docx or doc document file can not be opened because “the name in the end tag of the element must match the element type in the start tag”

  1. Thank you so so so so much. I spent literally one hour with microsoft support last night trying to recover this and in the end they did nothing. I wish I’d found this tutorial before calling them! Thank you so much, this was amazing.

    Liked by 1 person

  2. Hello, could you help me, I have a word document does not open, I tried the procedure you indicated, but will not work or do not apply it properly.

    Like

  3. Thank you so much!!!! You’ve rescued half of my master thesis!
    So happy! 🙂

    The only problem now, there are a lot of blank between some words. But this is really a small problem 😉

    Liked by 1 person

  4. I have the same problem, but I can’t see where the error code actually is. Could you kindly help me? Can I send you my file? I need to send this file to the vendor 😦

    Liked by 1 person

  5. I need help. I wasn’t able to use the Eclipse Indigo to format the xml code for some reason. I right clicked on my text.xml file inside the project I created but did not get the Source option. I download xml tools plugin for notepad++ and used that instead. I saved it and reopened the document and saw that the error code has changed from the previous line to 286 column 8.

    I reopened the xml file in notpad++ and went to that line. All I see on that line is

    I’m no coder and I’m not sure what to close that with if that is indeed the problematic area?
    Any advice is appreciated. Thank you.

    Liked by 1 person

  6. Oh thank goodness!! Thankyou very much for your tutorial! I am on the edge of losing my main master thesis. It took me almost 10 hours to try every options available, and finally I found your tutorial! Thankyou Thankyou Thankyou! Thankyou! Thankyou! I would literally kiss you if I could 🙂

    For everybody who’s still confused with eclipse and the rest of the step, this is the additional detail steps that I can give :
    1. Open Eclipse
    2. File > New > Project… > choose Java Folder > Java Project > Next > Insert Project Name>Finish
    3. File > New > Other.. > choose XML Folder > XML File > Next > Insert XML file name > choose the Java Project Folder that had been previously made > Finish
    4. Copy the content of document.xml (that being opened on notepad++) and paste them on the new xml file on Eclipse
    5. Place your cursor on the content area of that xml file > right click > Source > Format (It took quite a while in my case, around 15-30 mins, you must be patient)
    6. The content will be sorted neatly and vertically
    7. Ctrl + A > Ctrl + C (just copy the content)
    8. Move back to document.xml on notepad++, delete the original content of that file, and replace them (paste) with the new sorted one
    9. Don’t forget to save it!
    10. Continue with the rest of the steps from zihengsun’s tutorial : compressed the files to xxxx.zip, then replace .zip with .docx, and try to open it >> there will be another error windows >> see the details >> for example : line 433258 column 8 >> open the document.xml again with notepad++ and search the mistaken tag.
    Just check them, if all the code have their start and end tags completely. If not, you should add it your self. Good luck!

    Liked by 1 person

  7. Oh thank goodness!! Thankyou very much for your tutorial! I am on the edge of losing my main master thesis. It took me almost 10 hours to try every options available, and finally I found your tutorial! Thankyou Thankyou Thankyou! Thankyou! Thankyou! I would literally kiss you if I could🙂

    For everybody who’s still confused with eclipse and the rest of the step, this is the additional detail steps that I can give :
    1. Open Eclipse
    2. File > New > Project… > choose Java Folder > Java Project > Next > Insert Project Name>Finish
    3. File > New > Other.. > choose XML Folder > XML File > Next > Insert XML file name > choose the Java Project Folder that had been previously made > Finish
    4. Copy the content of document.xml (that being opened on notepad++) and paste them on the new xml file on Eclipse
    5. Place your cursor on the content area of that xml file > right click > Source > Format (It took quite a while in my case, around 15-30 mins, you must be patient)
    6. The content will be sorted neatly and vertically
    7. Ctrl + A > Ctrl + C (just copy the content)
    8. Move back to document.xml on notepad++, delete the original content of that file, and replace them (paste) with the new sorted one
    9. Don’t forget to save it!
    10. Continue with the rest of the steps from zihengsun’s tutorial : compressed the files to xxxx.zip, then replace .zip with .docx, and try to open it >> there will be another error windows >> see the details >> for example : line 433258 column 8 >> open the document.xml again with notepad++ and search the mistaken tag.
    Just check them, if all the code have their start and end tags completely. If not, you should add it your self. Good luck!

    Liked by 1 person

  8. Interesting facts: 1. The idea is mostly brilliant. 2. If you have a few hundred pages of document you may have to allocate more memory to Eclipse or similar software (alter values in .ini file). 3 It may take up to 4 h to format a large file even with plenty of allocated memory. 4. You don’t have to find the error in the script as it may be difficult. If you can spare some of the text you may delete a few tens/hundreds of lines from the script around the reported error line (make sure you delete complete structures or substructures of the code). Hope it helps for people in need.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s