How to fix Eclipse validation error "No grammar constraints detected for the document"?

103,275

Solution 1

Not sure if you ever resolved this satisfactorily but I ran across this posting today while working with some Spring configuration files in Eclipse 3.6. I could not get the error to go away in the Problems view in Eclipse no matter what, until I right-clicked on the problem and deleted it.

I figured it would come back if I revalidated and there was actually a problem and so far it hasn't. The thing is I had an almost identical Spring config file that wasn't showing the error.

It would seem that sometimes stuff just gets stuck in Eclipse. Not sure why but between this and files getting out of sync with the editors and having to force a refresh I guess I have to accept it.

Solution 2

Putting this at the top of any offending file works for me:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE project>

Solution 3

This is another way to turn off warnings for XML Documents that intentionally lack a DTP or XSD:

  1. Go to Menu Preferences,
  2. in the navig menu, i.e. the Left frame of the dialog-box, Choose: XML > XML Files > Validation
  3. in the config area, i.e the right frame of the dialog-box, choose: Validating Files > No grammar specified > Ignore (This is a select box) default setting is warning)

Solution 4

I am not an expert but a learner. I accidentally found an easy and stupid way to solve the problem. What you just need to do is:

Press ctrl + shift + F (it's a shortcut to format the file in Eclipse)

If this does not solve the problem then press the TAB key at the starting of this particular line
?xml version="1.0" encoding="UTF-8"? and not anywhere else (I don't not why, but this works. If anyone here knows why I will be very happy to know)

Then press ctrl + shift + F and save.

The warning will be gone, at least for me, you may try for yourself...

Solution 5

If this warning shows up it means the XML Validate function (which is different from the XML instance editor!) did not know what DTD or XSD to apply. This of course also means it did not actually check if the XML instance was compliant to any schema.

This is therefore a helpful warning, it should not be turned off (if you use the Validate menu function and expect it to do something).

You can use the preferences to make your schema known:

  • Open Preferences / XML Catalog / User Specified Entries
  • Click Add...
  • Enter the XSD file to use in "Location"
  • Select Key Type "Schema location" (in case you have a xsi:schemaLocation)
  • Enter the URL (second part of the location) matching the files content as "Key"
  • Press OK
  • Go to Problem view and delete the validation warning
  • Right-Click the XML File and Chose "Validate" again

Some public idenditfiers and schema locations are already contained in the "Plugin Specified Entries" (especially if you have WSTP installed). For those namespaces you do not get the warning (As it uses the system provided copy to validate).

Share:
103,275
cmcginty
Author by

cmcginty

Interests include Python, Gradle, C, Java, Git, Linux, Embedded. Find me on github https://github.com/cmcginty.

Updated on May 18, 2020

Comments

  • cmcginty
    cmcginty about 4 years

    Eclipse 3.5.2 is throwing an XML schema warning message:

    No grammar constraints (DTD or XML schema) detected for the document.
    

    The application.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <application
      xmlns="http://java.sun.com/xml/ns/javaee"
      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/application_5.xsd"
      version="5">
    
    </application>
    

    I do not want to disable the warning. How can I get Eclipse to correctly validate the XML document?