The markup declarations contained or pointed to by the document type declaration must be well-formed

 ̄綄美尐妖づ 提交于 2020-01-02 08:24:31

问题


I have written one XML, but in that XMLon very first line I am getting an error

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 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.

Please let me know why I am hitting this issue.


回答1:


I guess this is because of the extra spaces between < and ?xml and between ? and >.

Note that you also seem to have extra spaces at the begin and end of the doctype declaration.

Edit

OK, I found two other issues with your file:

  1. It seems you forgot the “a” in apache.org in the DTD uri.
  2. The DTD available at http://struts.apache.org/dtds/struts-2.0.dtd starts with an XML declaration (<?xml version="1.0" encoding="UTF-8"?>), which is forbidden at the beginning of a DTD (because a DTD is not an XML file).

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.




回答2:


When you create a dtd it always contains the lines

<!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.



来源:https://stackoverflow.com/questions/15588090/the-markup-declarations-contained-or-pointed-to-by-the-document-type-declaration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!