2
votes

When Eclipse detects an invalid XML document, in my case a web.xml file, it dumps the content model of the DTD and tells me that the element is invalid. This is quite unhelpful, since it ends up telling me that:

The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)".

In a 900-line web.xml file, the error is not easy to find.

How can I single out the first element which causes the document to be invalid?

2

2 Answers

2
votes

I would create a copy of the web.xml and cut the content in halves, (ensuring it stays well-formed) until I found the element. After that you add the remaining parts of your copied file.

2
votes

I know this is an old question, but for me it ended up being the order of the web.xml options. If you look at the error message, your elements need to be in the exact order listed in the error. For instance:

<web-app>

<display-name>LBSPing!</display-name>

<context-param>
    ...
</context-param>

<listener>
    ...
</listener>

<servlet>
    ...
</servlet>

<servlet-mapping>
    ...
</servlet-mapping>

</web-app>

For me, my context-params were after my servlet and listener nodes, which was causing my issue.