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

JavaEclipseJakarta EeXsd

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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

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

Solution 2 - Java

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 3 - Java

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

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

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

Solution 6 - Java

Add this to your xml file's very beginning:

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

Change RelativeLayout to your defined root layout ,then find xml file in left side, in layout folder, right click and select Validate.

Solution 7 - Java

in eclipse to avoid the "no grammar constraints (dtd or xml schema) detected for the document." i use to add an xsd schema file to the xml catalog under

"Window \ preferences \ xml \ xml catalog \ User specified entries".

Click "Add" button on the right.


Example:

<?xml version="1.0" encoding="UTF-8"?>
<HolidayRequest xmlns="http://mycompany.com/hr/schemas">
    <Holiday>
        <StartDate>2006-07-03</StartDate>
        <EndDate>2006-07-07</EndDate>
    </Holiday>
    <Employee>
        <Number>42</Number>
        <FirstName>Arjen</FirstName>
        <LastName>Poutsma</LastName>
    </Employee>
</HolidayRequest>

From this xml i have generated and saved an xsd under: /home/my_user/xsd/my_xsd.xsd

As Location: /home/my_user/xsd/my_xsd.xsd

As key type: Namespace name

As key: http://mycompany.com/hr/schemas


Close and reopen the xml file and do some changes to violate the schema, you should be notified.

Solution 8 - Java

I had some success going back to V1.4 of application.xsd. If anyone can explain why the JavaEE version does not work, I would appreciate it.

<?xml version="1.0" encoding="UTF-8"?>
<application
  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/application_1_4.xsd"
  version="1.4">

Solution 9 - Java

Here's what worked for me. I was using schemas without version numbers (e.g. spring-beans.xsd, and not spring-beans-4.1.xsd) and they probably got updated upstream. I assume the problem was that Eclipse kept a dirty cache of the old versions.

Fix :

  1. Go to Window -> Preference -> Network Connection -> Cache
  2. Remove all cached schemas.
  3. Delete all the no grammar constraints problems in problem view.
  4. Re-validate the project.

Solution 10 - Java

What I found worked for me was to remove the schemaLocation attribute completely then right click in the outline view and goto edit namespaces, then adding the schema location hint into the resulting dialog.

Solution 11 - Java

It can be because of your proxy settings. See this and this. You can try attaching javadoc by URL to a library without it. If it is okay in your browser, but not in your editor, then it's a connection problem. I solved the same problem by asking the admin about the proxy settings. Although all other applications did work, eclipse didn't, so I had to enter the config "manually". It would be great if developers added a button "check connection"...

Solution 12 - Java

Here's the working solution for this problem:

Step 1: Right click on project and go to properties

Step 2: Go to 'libraries' and remove the project's ' JRE system library'

Step 3: Click on 'Add library'-->'JRE System Library' -->select 'Workspace default JRE'

Step 3: Go to 'Order and Export' and mark the newly added ' JRE system library'

Step 4: Refresh and Clean the project

Eureka! It's working :)

Solution 13 - Java

Solution For Eclipse:

add <!DOCTYPE something> to the begining of each problematic XML,

after the xml tag <?xml version="1.0" encoding="utf-8"?>

you can write anything for doctype, but basically it's supposed to be manifest, activity, etc. from what I understand

Solution 14 - Java

I was just having this problem last night (using eclipse V.kepler). I am completely new to java and eclipse and I am trying to teach myself how to make an android app. While I was working on the lessons offered at developers.android.com I had input this into my main_activity_actions.xml file:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<!--  Search should appear as an action button -->
<item android:id="@+id/action_search"
      android:icon="@drawable/ic_action_search"
      android:title="@string/action_search"
      android:showAsAction="ifRoom"/>

</menu>

This gave me the same error as OP. I tried following the suggestion of adding

<!DOCTYPE project> 

just below the first line and it solved the issue.

Solution 15 - Java

What worked for me is to right click the xml-file in the tree (usually on the left hand side in eclipse) and clicked the validate. Since then, the warning never came back.

Solution 16 - Java

Editing Spring context files, I found that setting explicitly the version of the XSD removes the warning:

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.9.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

Solution 17 - Java

Non of the above mentioned solutions worked. It was working for Spring boot version 2.1.0.RELEASE but when i created project with spring boot version 2.3.0.RELEASE, i started getting
no grammar constraints (dtd or xml schema) referenced in the document issue.

I fixed it by updating Eclipse version which updates maven version as well. In my case i am using red hat developer studio so, Menu->Help->check for updates, It will scan and open the update window with Available updates. Check the update related to Eclipse version and Click Next->Next->Accept Terms->Finish.

Solution 18 - Java

for me it worked like a charm when I cut it (ctrl a + ctrl - X) and saved it back again (ctrl-s) ! the warning "No grammar constraints (DTD or XML schema) detected for the document" was gone for good!!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncmcgintyView Question on Stackoverflow
Solution 1 - JavaPlenus FrancklyView Answer on Stackoverflow
Solution 2 - JavaJason KratzView Answer on Stackoverflow
Solution 3 - JavaknbView Answer on Stackoverflow
Solution 4 - JavamadhaviView Answer on Stackoverflow
Solution 5 - JavaeckesView Answer on Stackoverflow
Solution 6 - Javaresw67View Answer on Stackoverflow
Solution 7 - Javauser1374968View Answer on Stackoverflow
Solution 8 - JavacmcgintyView Answer on Stackoverflow
Solution 9 - JavaMobiusView Answer on Stackoverflow
Solution 10 - JavaDeveloper ZView Answer on Stackoverflow
Solution 11 - JavapkopacView Answer on Stackoverflow
Solution 12 - Javauser2372633View Answer on Stackoverflow
Solution 13 - JavaAmir.FView Answer on Stackoverflow
Solution 14 - Javad3sperad0View Answer on Stackoverflow
Solution 15 - JavaWayneEraView Answer on Stackoverflow
Solution 16 - JavaDavid C.View Answer on Stackoverflow
Solution 17 - JavaSudoCoderView Answer on Stackoverflow
Solution 18 - JavaSheeba NancyView Answer on Stackoverflow