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

33,143

Solution 1

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

Solution 2

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

Solution 3

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 4

In my case I solved this problem by this

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

Solution 5

You could also add

<!DOCTYPE androidXML>

below

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

and then just right-click your project and select Validate

Share:
33,143

Related videos on Youtube

Hoornet
Author by

Hoornet

I am a self-taught android developer currently learning and developing apps for Android in Kotlin and Flutter.

Updated on February 11, 2020

Comments

  • Hoornet
    Hoornet about 4 years

    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"

  • Hoornet
    Hoornet almost 11 years
    do you have "xmlns:android="schemas.android.com/apk/res/android" in the dtd settings? I don't
  • Raghunandan
    Raghunandan almost 11 years
  • Hoornet
    Hoornet almost 11 years
    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
    Hoornet over 10 years
    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." :)
  • DavidF
    DavidF almost 10 years
    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.
  • r41n
    r41n almost 10 years
    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.
  • Armfoot
    Armfoot over 9 years
    @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 <!DOCTYPE ...> solution didn't work for me. So I'd not spend more time in trying to figure this out.
  • Rune
    Rune almost 9 years
    DOCTYPE Descriptions (DTDs) are very well explained here: xmlwriter.net/xml_guide/doctype_declaration.shtml Basically, it should be '<!DOCTYPE root_element>' or in your case: '<!DOCTYPE GridLayout>'