Warnings of valid HTML5 attributes in Eclipse

EclipseHtml

Eclipse Problem Overview


I use Eclipse and I write jsp files with HTML5 content. So I have for example this line:

<div class="test" data-role="test123">

In Eclipse I get the warning:

> Undefined attribute name (data-role)

What needed to be done so these warnings won't appear anymore? In HTML5 this attribute is allowed (data-*) as you can see here: http://ejohn.org/blog/html-5-data-attributes/

Eclipse Solutions


Solution 1 - Eclipse

It seems like Eclipse still has some problems validating HTML5 elements and attributes even now.

I'm running Mars 4.5.1 and I have had warnings about the <main> element, despite the fact that there are no warnings about the <section> element.

But there is a solution!

Window > Preferences > Web > HTML Files > Validation

Window > Preferences > Web > HTML Files > Validation

Here you can tick the Ignore specified element names in validation checkbox and enter the names of any elements which Eclipse is incorrectly warning you about.

In your case, you will want to tick the Ignore specified attribute names in validation checkbox and enter the data-role attribute.

After you click 'Apply', Eclipse will ask you to do a full validation of the project. Select 'Yes' and the changes will take effect.

No more squiggly yellow lines YAY! :D

Solution 2 - Eclipse

Your doctype

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
         "http://www.w3.org/TR/html4/loose.dtd">

is for HTML 4.01.

data-* attributes were added in HTML 5. The doctype for HTML 5 is basically either

<!DOCTYPE html SYSTEM "about:legacy-compat">

or

<!DOCTYPE html>

Solution 3 - Eclipse

Newer versions of Eclipse support HTML5 tags and the data-* attributes allowed in HTML5. However, when using the role attribute the proper syntax according to the ARIA Roles Model and XHTML Role Attribute Module is not to prefix the role attribute with data-* leaving just role and not data-role.

So <ul role="menubar"> is more correct than <ul data-role="menubar">. The validity of the syntax can be checked using the (X)HTML5 Validator. jQuery Mobile uses quite extensively the data-role attribute, though I'm not sure why.

Note: If you upgrade and you're still getting warnings on data-* attributes you may want to consider updating or removing any installed syntax-checkers such as JTidy. As of Indigo Service Release 1 the role attribute continues to trigger an undefined attribute warning in Eclipse by default.

Solution 4 - Eclipse

I used this one with Aptana 3.6 when I'am coding AngularJS

> Window > Preferences

Choose Ignore Proprietary Attributes

Solution 5 - Eclipse

I use the Aptana Studio plugin on Mac OS X; if I go Eclipse > Preferences > Aptana Studio > Validation > HTML, and create the filter *data-role* I no longer get this warning.

I believe on Windows it is Window > Preferences > Aptana Studio > Validation > HTML

Aptana HTML Validation

Solution 6 - Eclipse

Eclipse 3.6 introduced a new field under:

Validation -> HTML Syntax: Ignore specified attribute names in validation

Add the OpenGraph, RDFa or other non-HTML5 attributes you want the validator to ignore:

Ignore specified attribute names in validation

You will need to re-validate the project, then the warnings will be gone.

Solution 7 - Eclipse

Eclipse observes the DOCTYPE declaration. In my case, the solution was using the code above at the first line of the files containing HTML code:

<!DOCTYPE html>

Related to that, there's this other question, already answered:

https://stackoverflow.com/questions/3147799/why-do-we-need-doctype-to-the-html-jsp-pages

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
QuestionTimView Question on Stackoverflow
Solution 1 - EclipseRedtamaView Answer on Stackoverflow
Solution 2 - EclipseMS IbrahimView Answer on Stackoverflow
Solution 3 - EclipsevhsView Answer on Stackoverflow
Solution 4 - Eclipsevanduc1102View Answer on Stackoverflow
Solution 5 - EclipseTMBView Answer on Stackoverflow
Solution 6 - EclipsevallismortisView Answer on Stackoverflow
Solution 7 - EclipseThiago MunizView Answer on Stackoverflow