cmcginty
cmcginty

Reputation: 117076

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

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?

Upvotes: 60

Views: 108406

Answers (18)

SudoCoder
SudoCoder

Reputation: 137

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.

Upvotes: 0

David C.
David C.

Reputation: 1

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

Upvotes: 0

vareste
vareste

Reputation: 445

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.

Upvotes: 6

Sheeba Nancy
Sheeba Nancy

Reputation: 65

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

Upvotes: -1

Mobius
Mobius

Reputation: 45

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.

Upvotes: 1

eckes
eckes

Reputation: 10423

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

Upvotes: 7

WayneEra
WayneEra

Reputation: 133

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.

Upvotes: 0

Jason Kratz
Jason Kratz

Reputation: 506

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.

Upvotes: 46

d3sperad0
d3sperad0

Reputation: 9

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.

Upvotes: 0

Amir.F
Amir.F

Reputation: 1961

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

Upvotes: 0

madhavi
madhavi

Reputation: 79

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

Upvotes: 7

Gnaural
Gnaural

Reputation: 824

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

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

Upvotes: 67

user2372633
user2372633

Reputation: 25

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

Upvotes: 0

knb
knb

Reputation: 9303

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)

Upvotes: 35

zxmax
zxmax

Reputation: 151

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.

Upvotes: 3

pkopac
pkopac

Reputation: 1035

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

Upvotes: 0

Developer Z
Developer Z

Reputation: 41

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.

Upvotes: 0

cmcginty
cmcginty

Reputation: 117076

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

Upvotes: 2

Related Questions