60

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?

Grzegorz Oledzki
  • 23,614
  • 16
  • 68
  • 106
cmcginty
  • 113,384
  • 42
  • 163
  • 163
  • hm, I still can't reproduce the warning on the version of Galileo (3.5) that I have installed. Sorry :( – Matt Ball Jan 28 '11 at 21:33
  • using Helios release, I pasted your xml into a new file NewFile.xml and saw this warning message; I then renamed the file (arbitrary name) and the warning disappeared. Weird, but easy enough to try... – kem Jan 28 '11 at 21:35
  • 1
    Could it be that you need a proxy to connect to the internet? – biziclop Jan 28 '11 at 21:56
  • no luck on renaming; internet is working on the machine – cmcginty Jan 28 '11 at 22:37
  • wow, this one really turned into a popular question ... – cmcginty May 02 '13 at 09:10
  • 1
    possible duplicate of [No grammar constraints (DTD or XML schema) detected for the document](http://stackoverflow.com/questions/4551783/no-grammar-constraints-dtd-or-xml-schema-detected-for-the-document) – avalancha Oct 27 '14 at 12:23

18 Answers18

64

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

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE project>
Gnaural
  • 794
  • 8
  • 9
  • 3
    For me this just stops validation at all, and therefore remove the error message – AlexWien Jan 23 '15 at 19:04
  • 2
    Tried this (on Eclipse Luna). Led to a new warning: _"SchemaLocation: schemaLocation value = 'http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd' must have even number of URI's."_. See [acdcjunior's answer](http://stackoverflow.com/a/16720774/1744774) and [MahmoudS' question](http://stackoverflow.com/questions/7583038/what-is-the-use-of-faces-config-xml-in-jsf-2) for this. – Gerold Broser Jun 13 '15 at 15:48
46

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.

avalancha
  • 1,457
  • 1
  • 22
  • 41
Jason Kratz
  • 496
  • 4
  • 7
  • this is getting the votes, so i'll mark it as correct – cmcginty Apr 03 '14 at 19:41
  • 1
    Agree, I couldn't solve the issue by whatsoever methods shown below. Finally, I decided to just let it out of my sight by deleting it, as ultimately, it didn't affect the project. Thanks @Jason – Nirav Zaveri Dec 02 '14 at 09:01
  • 2
    This worked for me. However there was still an annoying warning sign in the code file in the project manifest. Adding ` ` solved this also ! –  Feb 01 '17 at 12:18
35

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)
knb
  • 9,138
  • 4
  • 58
  • 85
7

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

Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
madhavi
  • 79
  • 1
  • 1
6

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

eckes
  • 10,103
  • 1
  • 59
  • 71
  • 1
    Actually this is the real answer that provides the solution. This answer should be accepted one. – TomR Jul 16 '21 at 11:06
5

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.

resw67
  • 139
  • 3
  • 6
3

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.

zxmax
  • 151
  • 1
  • 3
2

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">
cmcginty
  • 113,384
  • 42
  • 163
  • 163
  • I still think that the internet proxy theory is most likely. Are you sure that Eclipse is able to perform remote HTTP requests? The fact that you can do this from your web browser or the command line doesn't prove that Eclipse can do it. (And the validator may be using a hard-wired copy of the 1.4 xsd.) – Stephen C Jan 29 '11 at 01:02
  • 2
    I can run "check for updates" fine. If there is another way to verify that eclipse has network access, please post it – cmcginty Jan 29 '11 at 02:27
  • I guess this is because the "old" schema location is provided by the JST standard schema plugin. You can see it in the XML Catalog Plugin Specified Entries. My JST (Eclipse MArs) also ships "Namespace Name http://xmlns.jcp.org/xml/ns/javaee/application_5.xsd" however. – eckes Jul 28 '15 at 16:43
1

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.

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127
Mobius
  • 45
  • 4
0

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

0

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

Amir.F
  • 1,911
  • 7
  • 29
  • 52
0

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.

d3sperad0
  • 9
  • 1
0

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.

WayneEra
  • 133
  • 1
  • 6
0

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.

0

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">
David C.
  • 1
  • 2
0

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.

SudoCoder
  • 119
  • 1
  • 9
0

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

pkopac
  • 986
  • 1
  • 13
  • 21
-1

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

Sheeba Nancy
  • 75
  • 1
  • 8