在 Excel 中打开 xml 文件时出现错误 -1072896636“DTD 禁止”,我该怎么办?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22403907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:01:04  来源:igfitidea点击:

Error -1072896636 "DTD Prohibited" when opening xml file in Excel, what do I do?

xmlexceldtd

提问by Hanako Seishin

I'm trying to open an XML file in Excel 2013, but it says it can't do that because "DTD prohibited". I've searched for the solution, but all I found are some pieces of code that are supposed to solve the problem.

我试图在 Excel 2013 中打开一个 XML 文件,但它说它不能这样做,因为“DTD 被禁止”。我已经搜索了解决方案,但我发现的只是一些应该解决问题的代码。

But I don't get it at all! What code? I'm just opening the file, I'm not writing a program or anything. Should I recite that code aloud before opening a file or what? Sorry, but I find it really absurd.

但我完全不明白!什么代码?我只是打开文件,我没有写程序或任何东西。我应该在打开文件之前大声背诵该代码还是什么?对不起,但我觉得这很荒谬。

Is there some solution to just open the file without writing a program for it? And if not, what should I do with this code?

是否有一些解决方案可以只打开文件而不为其编写程序?如果没有,我应该如何处理这段代码?

The code I'm talking about is the following

我正在谈论的代码如下

Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
xmlDoc.setProperty "ProhibitDTD",False
xmlDoc.load xmltoload.xml

I've discovered that the file may be supposed to be opened in Word, not Excel, but the Word 2013 gives me the same error.

我发现该文件可能应该在 Word 中打开,而不是在 Excel 中打开,但 Word 2013 给了我同样的错误。

Answer:
It appeared the file was supposed to be opened in Excel after all. I've found on the Internet that Office 2007 and older doesn't prohibit DTD whatever that is. So I successfully bypassed the problem by opening the needed file in Excel 2003.

答:
看来该文件应该是在 Excel 中打开的。我在 Internet 上发现 Office 2007 及更早版本并不禁止 DTD。所以我通过在 Excel 2003 中打开所需的文件成功绕过了这个问题。

回答by constra

The workaround is pretty easy. Open the XML file and delete the line that is referring to a DTD location. Excel will then create an XML schema according to your XML file.

解决方法很简单。打开 XML 文件并删除引用 DTD 位置的行。然后 Excel 将根据您的 XML 文件创建一个 XML 架构。

回答by Mooseknuckles

All XML documents rely upon a definition of what fields are allowed to exist and what values are allowed to exist within each of those fields. These are defined within each XML file by linking to either a Document Type Definition ("DTD") or an XML Schema file.

所有 XML 文档都依赖于对允许存在哪些字段以及允许在每个字段中存在哪些值的定义。这些是通过链接到文档类型定义 (“DTD”) 或 XML 架构文件在每个 XML 文件中定义的。

My understanding is that Excel 2007 and later do NOT support DTD. Instead, they expect that your XML file will reference an XML Schema.

我的理解是 Excel 2007 及更高版本不支持 DTD。相反,他们希望您的 XML 文件将引用一个 XML 架构。

So, your underlying problem is that your XML file is referencing a DTD file and you need to convert your DTD file to an XML Schema file (you can verify this by opening the document with a program like Notepad++ and looking at the raw text.)

因此,您的潜在问题是您的 XML 文件引用了 DTD 文件,您需要将 DTD 文件转换为 XML 架构文件(您可以通过使用 Notepad++ 等程序打开文档并查看原始文本来验证这一点。)

There are a lot of tools out there that help you do this but, frankly, I've been trying to get them all to work for a few hours and still don't have Excel opening my XML (ran across this post googling the same error code.)

有很多工具可以帮助你做到这一点,但坦率地说,我一直试图让它们全部工作几个小时,但仍然没有 Excel 打开我的 XML(在这篇文章中谷歌搜索相同错误代码。)

If you are just trying to open an XML file one-off you probably don't want to put that much effort into it -- but if I figure out a quick and easy solution I'll come update.

如果您只是想一次性打开一个 XML 文件,您可能不想为此付出太多努力——但如果我想出一个快速简便的解决方案,我会来更新的。

If you just need to open it there is a free program you can download that converts XML to CSV:

如果您只需要打开它,您可以下载一个免费程序,将 XML 转换为 CSV:

http://xmltocsv.codeplex.com/

http://xmltocsv.codeplex.com/

I tried it and it worked great -- got my file to open in Excel 2013 immediately. Problem solved for now.

我试过了,效果很好——让我的文件立即在 Excel 2013 中打开。问题暂时解决。

Of course, the point of XML is that data can relate to other data with context and that is lost without a proper schema or DTD file. But if you just want the file to open, this should work for now (for those who don't still have Excel 2003 lying around, though I imagine that's just as easy for you.)

当然,XML 的重点是数据可以与其他具有上下文的数据相关联,并且在没有正确模式或 DTD 文件的情况下会丢失。但是,如果您只想打开文件,那么现在应该可以使用(对于那些仍然没有 Excel 2003 的人,尽管我想这对您来说同样容易。)

回答by mrtsherman

Recently I've seen this error resurface in ClickOnce versions of Excel associated with Office365 accounts. It does not affect Excel versions that are distributed via CD/ISO. You can tell the difference between the two via version numbers.

最近,我在与 Office365 帐户关联的 Excel 的 ClickOnce 版本中看到此错误再次出现。它不会影响通过 CD/ISO 分发的 Excel 版本。您可以通过版本号区分两者之间的区别。

Go to File | Account | Click the "About Excel" button

转到文件 | 帐号 | 单击“关于 Excel”按钮

  • 16.0.4456.1003 - CD/ISO
  • 16.0.7571.7063 - ClickOnce
  • 16.0.4456.1003 - CD/ISO
  • 16.0.7571.7063 - ClickOnce

The error is triggered when the XML file has no DTD andno XML Schema file. When attempting to refresh the data connections, you get the DTD error. If you actually edit the XML query, the data will indeed update. I suspect that this is a bug.

当 XML 文件没有 DTDXML Schema 文件时会触发该错误。尝试刷新数据连接时,您会收到 DTD 错误。如果您实际编辑 XML 查询,数据确实会更新。我怀疑这是一个错误。