Bogus Eclipse warning for web.xml: “No grammar constraints (DTD or XML schema) detected for the document.”

StackOverflow https://stackoverflow.com/questions/322155

  •  11-07-2019
  •  | 
  •  

Question

The top of my web.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
    version="2.5">

But I still get the warning from Eclipse (Ganymede) that no XML schema is detected, and schema violations are not being warned about. Other XML files in my project (Spring Framework configuration files for example) don't have the warning and do give correct warnings about schema violations.

How do I get the schema checking working and hopefully the warning to go away? The server does run correctly. It just appears to be an IDE issue.

Was it helpful?

Solution

Perhaps try:

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

Instead of:

http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd

Also, the <!DOCTYPE ...> is missing:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<web-app
  xmlns="http://java.sun.com/xml/ns/j2ee" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">
  <!-- ... -->
</web-app>

OTHER TIPS

I hate that warning too. Specially because it appears in XML files that you haven't written but appear in your project for whatever reason (if you use MAVEN it's hell).

With Eclipse 3.5+ you can easily remove this validation rule. Go to Preferences-->XML-->XML FILES --> Validation and Select "ignore".

You may also have to do a Project -> Clean for the validation warnings to go away.

alt text

Clear the cache for stored validation files.

Window > Preferences > General > Network Connections > Cache then remove all. Now go validate the file and see if that clears things up.

This happed to me and clearing the cache for the validation was the only way to get it functioning properly again. The advice for clearing dirty cache was found here.

If you have the same (missleading) error message because your XML Editor was not finding the XSD file, you can add a catalog entry.

You pick the URL specified for the schema, for a declaration like

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
                      http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"

The URL of the schema file (http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd) is specified for the namespace http://java.sun.com/xml/ns/j2ee. You can now redirect the location of the file with the workspace catalog in Eclipse:

Preferences -> XML -> XML Catalog -> Add..

Use

Key Type = Schema Location
Key = http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd

And then you can use the file chooser to pick actually a XSD file on the filesystem or the workspace.

The problem is two-fold:

  1. Eclipse ships with a cache of a lot of well-known XSD's. The name space and/or location you provide does not match any of these.
  2. So Eclipse tries to go looking for the XSD on the internet on the URI provided (may just work). Unfortunately it appears that after Oracle revised java.sun.com this mechanism just times out in Eclipse (apparently the server redirects to the homepage instead of simply saying "does not exist, sorry").

When you revise to the correct values for Java EE 5, the entry in the cache will be found and Eclipse will be happy.

you can also see my answer for similar question on.

Basically, just write your xml to conform to required rule

Add this <!DOCTYPE ...> to your xml file. Please put it under <?xml ...>:

<!DOCTYPE ??? PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

??? = Your root element, now if your sub-element name is using a html reserved word you might be catching some errors, all you have to do is change them to a non-reserved word.

For example:
If your current sub-element is <img>, change it to <pic>...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top