13

I have the same problem as many here, but i DO HAVE xmlns:android and the xml=... tags. Still I have the same error. I don't wan't just click the ignore instead of warning in the settings so hence the question here posted.

The source is:

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


</GridLayout>

The error:

"No grammar constraints (DTD or XML schema) detected for the document. grid_layout_test2.xml /SomeProject/res/layout line 1 XML Problem"

Community
  • 1
  • 1
Hoornet
  • 1,398
  • 3
  • 18
  • 30

8 Answers8

20

For me it was a Problem with character encoding and unix filemode running eclipse on Windows:

Just marked the complete code, cutted and pasted it back (in short: CtrlA-CtrlX-CtrlV) and everything was fine - no more "No grammar constraints..." warnings

user3022856
  • 259
  • 3
  • 2
  • 1
    worked for me. add to copy from eclipse (control c), pasted in Notepad (control v), then selected it all in notepad (control a), copied it (control c) and finally pasted it back into eclipse. Pasting and copying from notepad removes all text formatting since notepad only supports plain text. – DavidF Jun 09 '14 at 04:36
  • 2
    Worked pretty well, thank you. Although on some occasions I had to cut\paste\save\cut\paste to make it work. After the first paste Eclipse moved the warning marker to the end of the file, clearly some encoding or bad char issue. – r41n Jun 19 '14 at 14:53
13

I retrieve a solution from a bug issue :

  1. Click Window > Preferences > XML > XML Files > Validation
  2. Change the setting 'validating files'>'No grammar specified' from warning to ignore.
  3. Re-validate your project. No more warnings now.

It works for me.

Be careful, my solution is a kind of "I do not understand so that I prefer to deactivate"...

AntoineP
  • 3,035
  • 1
  • 19
  • 22
  • 4
    Thank you, but this is exactly what i didn't want. If you take a look at my question once again you will see that: " I don't wan't just click the ignore instead of warning in the settings so hence the question here posted." :) – Hoornet Nov 27 '13 at 15:12
  • 1
    @Hoornet it seems to be a bug in Eclipse, since even after deleting all the content from one of the files and saving it, the warning still remained. With some files I managed to get the warning off by doing the CtrlA-CtrlX-CtrlV, but once I ignored all warnings as this answer explains and placed the __no grammar__ back on to __warning__ status, those same files had the same warning again... The ` ` solution didn't work for me. So I'd not spend more time in trying to figure this out. – Armfoot Aug 31 '14 at 16:03
4

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
  • 2
    DOCTYPE Descriptions (DTDs) are very well explained here: https://xmlwriter.net/xml_guide/doctype_declaration.shtml Basically, it should be ' ' or in your case: ' ' – Rune Jul 08 '15 at 19:11
4

In my case I solved this problem by this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
Rahul Soni
  • 86
  • 4
1

You could also add

<!DOCTYPE androidXML>

below

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

and then just right-click your project and select Validate

xdevs23
  • 3,824
  • 3
  • 20
  • 33
0

try the below

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:id="@+id/grid"
      android:layout_height="match_parent" >

</GridLayout>
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • do you have "xmlns:android="http://schemas.android.com/apk/res/android" in the dtd settings? I don't – Hoornet Jun 28 '13 at 10:41
  • try this http://stackoverflow.com/questions/4551783/no-grammar-constraints-dtd-or-xml-schema-detected-for-the-document – Raghunandan Jun 28 '13 at 10:44
  • that link isn't current. For example, the answer says that yone should select: As key type: Namespace name But this option doesn't exist any more... – Hoornet Jun 28 '13 at 11:04
0

Move marked files outside project folder.( or Move the folder containint marked files.) Reflesh the project.(Select the project in Project explorer, ->) Move back files. Reflesh the project.

0

simple way is first select all(ctrl+a) cut it (ctrl+x) than past, same error comes on most bottom do same process again and save it, angain do the above process, than your xml file is free from this type of error.