xml 文档类型声明包含或指向的标记声明必须格式正确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15588090/
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
The markup declarations contained or pointed to by the document type declaration must be well-formed
提问by user1928403
I have written one XML, but in that XMLon very first line I am getting an error
我已经写了一个 XML,但是在 XML 的第一行我收到一个错误
The markup declarations contained or pointed to by the document type declaration must be well-formed
文档类型声明包含或指向的标记声明必须格式正确
below is that XML (space after angular brackets is intentional)
下面是那个 XML(尖括号后的空格是有意的)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apche.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="getTutorial" class="org.koushik.javabrains.action.TutorialAction">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
first line (<?xml version="1.0" encoding="UTF-8"?>) is throwing the error.
第一行 ( <?xml version="1.0" encoding="UTF-8"?>) 抛出错误。
Please let me know why I am hitting this issue.
请让我知道为什么我会遇到这个问题。
回答by Etienne Miret
I guess this is because of the extra spaces between <and ?xmland between ?and >.
我想这是因为之间的多余的空格<和?xml之间 ?和>。
Note that you also seem to have extra spaces at the begin and end of the doctype declaration.
请注意,您似乎在 doctype 声明的开头和结尾处也有额外的空格。
Edit
编辑
OK, I found two other issues with your file:
好的,我发现您的文件还有两个问题:
- It seems you forgot the “a” in apache.org in the DTD uri.
- The DTD available at http://struts.apache.org/dtds/struts-2.0.dtdstarts with an XML
declaration (
<?xml version="1.0" encoding="UTF-8"?>), which is forbidden at the beginning of a DTD (because a DTD is notan XML file).
- 您似乎忘记了 apache.org 中 DTD uri 中的“a”。
- http://struts.apache.org/dtds/struts-2.0.dtd 上提供的 DTD以 XML 声明 (
<?xml version="1.0" encoding="UTF-8"?>) 开头,这在 DTD 的开头是被禁止的(因为 DTD不是XML 文件)。
If the first error is the one causing the trouble, it will be easy to fix. However, the second error is on the struts developers side. I guess most XML parsers ignores it (otherwise the struts team would have fixed it a long time ago), but if you have an XML parse that do complain about it, I'm afraid your only option is to switch to another one.
如果第一个错误是导致问题的原因,则修复起来很容易。然而,第二个错误是在 struts 开发人员方面。我猜大多数 XML 解析器都会忽略它(否则 struts 团队早就修复了它),但是如果您有一个 XML 解析器确实抱怨它,恐怕您唯一的选择是切换到另一个。
回答by Sathish Kumar G
When you create a dtd it always contains the lines
创建 dtd 时,它始终包含行
<!DOCTYPE…. [
...
]>
Simply remove the first and last line declaring the DTD data, since those are only to be used when having the DTD within your XML file.
只需删除声明 DTD 数据的第一行和最后一行,因为只有在 XML 文件中包含 DTD 时才会使用这些行。

