如何调试损坏的docx文件?

Mar*_*nox 15 xml debugging corrupt docx

我有一个问题,其中.doc和.pdf文件出来正常但.docx文件出现损坏.

为了解决这个问题,我试图调试为什么.docx已损坏.

我了解到docx格式在额外字符方面比.pdf或.doc更严格.因此,我搜索了docx文件中的各种xml文件,查找无效的XML.但我找不到任何东西.这一切都很好.

我一直在检查的xml文件

有人可以建议我现在去调查吗?

更新:

文件夹中文件的完整列表如下:

/_rels
    .rels

/customXml
    /_rels
        .rels
    item1.xml
    itemProps1.xml

/docProps
    app.xml
    core.xml

/word
    /_rels
        document.xml.rels
    /media
        image1.jpeg
    /theme
        theme1.xml
    document.xml
    fontTable.xml
    numbering.xml
    settings.xml
    styles.xml
    stylesWithEffects.xml
    webSettings.xml

[Content_Types].xml
Run Code Online (Sandbox Code Playgroud)

更新2:

我还应该提到腐败的原因几乎肯定是代表我的一个糟糕的二进制文件POST.

为什么docx文件被二进制文件损坏,但.doc和.pdf都没问题?

更新3:

我已经尝试了各种docx修复工具的演示.他们似乎都修复了文件,但没有提供错误原因的线索.

我的下一步是使用修复版本检查损坏文件的内容.

如果有人知道docx修复工具提供了一个体面的错误消息,我会很感激听到它.事实上,我可能会将其作为一个单独的问题发布.

更新4(2017)

我从未解决过这个问题.我已经尝试了下面答案中建议的所有工具,但它们都不适用于我.

自从0000Sublime Text打开.docx后,我已经进一步发展并找到了一个缺失块.这里新问题的更多细节:httpwebrequest期间.docx文件中可能导致这种损坏的原因是什么?

小智 9

我使用“Open XML SDK 2.5 Productivity Tool”(http://www.microsoft.com/en-us/download/details.aspx?id=30425)来查找超链接引用损坏的问题。

您必须先下载/安装 SDK,然后才是工具。该工具将打开并分析文档中的问题。


Blu*_*oth 8

晚了很多年,但我发现这对我来说确实有效。(来自https://msdn.microsoft.com/en-us/library/office/bb497334.aspx

(wordDoc 是一个WordprocessingDocument

using DocumentFormat.OpenXml.Validation;

        try
        {
            var validator = new OpenXmlValidator();
            var count = 0;
            foreach (var error in validator.Validate(wordDoc))
            {
                count++;
                Console.WriteLine("Error " + count);
                Console.WriteLine("Description: " + error.Description);
                Console.WriteLine("ErrorType: " + error.ErrorType);
                Console.WriteLine("Node: " + error.Node);
                Console.WriteLine("Path: " + error.Path.XPath);
                Console.WriteLine("Part: " + error.Part.Uri);
                Console.WriteLine("-------------------------------------------");
            }

            Console.WriteLine("count={0}", count);
        }

        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
Run Code Online (Sandbox Code Playgroud)


edi*_*999 5

通常,当特定 XML 文件出现错误时,Word 会告诉您错误发生在哪个文件的哪一行。所以我相信问题来自文件的压缩,或者文件夹结构。

这是Word文件的文件夹结构:

.docx格式是一个包含以下文件夹的压缩文件:

+--docProps
|  +  app.xml
|  \  core.xml
+  res.log
+--word //this folder contains most of the files that control the content of the document
|  +  document.xml //Is the actual content of the document
|  +  endnotes.xml
|  +  fontTable.xml
|  +  footer1.xml //Containst the elements in the footer of the document
|  +  footnotes.xml
|  +--media //This folder contains all images embedded in the word
|  |  \  image1.jpeg
|  +  settings.xml
|  +  styles.xml
|  +  stylesWithEffects.xml
|  +--theme
|  |  \  theme1.xml
|  +  webSettings.xml
|  \--_rels
|     \  document.xml.rels //this document tells word where the images are situated
+  [Content_Types].xml
\--_rels
   \  .rels
Run Code Online (Sandbox Code Playgroud)

好像你只有word文件夹里面的东西,不是吗?如果这不起作用,您能否发送损坏的 Docx 或将您的文件夹结构张贴在您的 zip 中?