📜 ⬆️ ⬇️

An interesting task for experts

In the process of writing plugins for jQuery, I faced the need to add extended attributes to some well-known tags to facilitate the transfer of parameters to plugins (it turns out nice and simple), but I also want to validate the page without any problems. A small experiment set a choice: either valid html or extended attributes ...

For normal validation of html, it was decided to describe extended attributes in the document description:

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[
<! ATTLIST input
lookup:url CDATA # IMPLIED
lookup:targets CDATA # IMPLIED
>
] >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" />
< title > test </ title >
</ head >
< body >
< input type ="text" maxlength ="50" size ="20" class ="lookup" name ="l1"
lookup:url ="/find.aspx?q="
lookup:targets ="id:MyHidden1, id:MySpan1.text, text:MySpan2.text" />
</ body >
</ html >



This html passes validation perfectly, ideal for a plugin, but! in browsers (Chrome, IE8, FF3) at the beginning of the document two characters "]>" are displayed and this spoils everything.
')
Options with external dtd file, etc. tried - validation fails.

Should I dig further or throw an idea with extended attributes and valid html? Or maybe someone will have an idea how to get around this?

Total. Thank you all for the discussion, I deliberately did not participate in the process. Special thanks to tenshi and SelenIT for explanatory links, I just didn’t have enough step to import DTD in my options.

So the result is: write your DTD file, import the desired DTD in it
<!-- include XHTML1.1 -->
<! ENTITY % xhtml1t . dtd PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
%xhtml1t.dtd;
<!-- -->
<! ATTLIST input
lookup:url CDATA # IMPLIED
lookup:targets CDATA # IMPLIED
>

Then we register Doctype on the page
<! DOCTYPE html PUBLIC "-//My//DTD XHTML MyExt//RU" "http://my.site.ru/_static/test.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
...

Validation passes, the document looks fine. However, another question is how browsers will perceive this.

By the way, the document must be valid or not about constant disputes - for me personally, validation is useful: I use validation to check the page code and search for jambs in the generated html, and I don’t really want to wade between the “extra” errors of the validator. Many have their own well-established opinion and persuade them to enter into polemics on this issue, too.

Source: https://habr.com/ru/post/57006/


All Articles