How to check html syntax using DocType:strict

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
rag_gupta
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Tue Nov 30, 2010 10:17 pm
Contact:

How to check html syntax using DocType:strict

Post by rag_gupta » Mon Jul 18, 2011 12:40 pm

My sites are all using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Before pasting into my CMS based sites I check the html code (without any html/body tags) with my cse v10.

If I'm checking an online web page I suppose CSE picksup the DocType from the page and does validation as per it.

But for my bits and pieces of html code how to I force it to use the strict DTD?

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3453
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: How to check html syntax using DocType:strict

Post by Albert Wiersch » Tue Jul 19, 2011 6:57 pm

Hello,

I'm sorry for the delay.

I think the best way to do this is to append the "start validation" program using the Configuration Editor. Try this:

* Press Ctrl+F5 in CSE HTML Validator to open the Configuration Editor
* Go to the Programs tab and select the Start validation program
* Add this to the end of the program:

Code: Select all

if isFlagSet(180) {
 MessageEx(13,2011071901,#MSG_COMMENT,'[180] Simulating a XHTML 1.0 Strict DOCTYPE (if no DOCTYPE is encountered).');
 setValueInt(3,2+32+128);
}
else {
 MessageEx(13,2011071902,#MSG_COMMENT,'[180] DOCTYPE simulation off.');
}
* Finally, save your custom config file to a new filename and set the new config file to the default to use

That should simulate an XHTML 1.0 Strict document if there is no DOCTYPE. You can uncheck flag 180 to undo this behavior.
Image
Albert Wiersch

rag_gupta
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Tue Nov 30, 2010 10:17 pm
Contact:

Re: How to check html syntax using DocType:strict

Post by rag_gupta » Wed Jul 20, 2011 1:28 am

I've done exactly the way you've specified but it isn't giving any error message for this html code:

Code: Select all

<p> hello
Also I see in Validator Engine->Flags->180 is checked

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3453
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: How to check html syntax using DocType:strict

Post by Albert Wiersch » Wed Jul 20, 2011 9:09 am

I'm sorry. It looks like more was needed than I first thought... please use this instead:

Code: Select all

if isFlagSet(180) {
  MessageEx(13,2011071901,#MSG_COMMENT,'[180] Simulating a XHTML 1.0 Strict DOCTYPE.');
  setValueInt(3,2+32+128);

  activateCategory(33,1);
  setValueInt(3,32);

  setFlag(1,65536,1);
  setFlag(1,64,1);
  setFlag(1,262144,1);
  setFlag(1,131072,1);
  setFlag(1,524288,1);
  setFlag(1,1,1);
  setFlag(1,4194304,1);
  setFlag(9,2,1);

  setFlag(1,1048576,1);
  setValueString(1,"For better backward compatibility with HTML, a space character should precede the '/' character.");
}
else {
  MessageEx(13,2011071902,#MSG_COMMENT,'[180] DOCTYPE simulation off.');
}
I think that should work, however, encountering a real DOCTYPE will not change many of those options back to the default so you may need to toggle flag 180 back and forth when switching to & from XHTML or the validator may try to enforce some XHTML constraints on HTML documents.
Image
Albert Wiersch

rag_gupta
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Tue Nov 30, 2010 10:17 pm
Contact:

Re: How to check html syntax using DocType:strict

Post by rag_gupta » Wed Jul 20, 2011 9:23 am

What are those options? I wish validation from typed code or from url should give same validation results.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3453
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: How to check html syntax using DocType:strict

Post by Albert Wiersch » Wed Jul 20, 2011 9:32 am

rag_gupta wrote:What are those options? I wish validation from typed code or from url should give same validation results.
This should help (includes comments):

Code: Select all

 setFlag(1,65536,1);    // CSEVALFLAG1XMLCOMPAT (65536)
 setFlag(1,64,1);       // CSEVALFLAG1REQUIREOPTIONALENDTAGS (64)
 setFlag(1,262144,1);   // CSEVALFLAG1REQUIREQUICKCLOSE (262144)
 setFlag(1,131072,1);   // CSEVALFLAG1REQUIREQUOTEDATTVALUES (131072)
 setFlag(1,524288,1);   // CSEVALFLAG1NOUPPERCASE (524288)
 setFlag(1,1,1);        // CSEVALFLAG1CHECKNESTING (1)
 setFlag(1,4194304,1);  // CSEVALFLAG1REQUIREATTVALUES (4194304)
 setFlag(9,2,1);        // CSEVALFLAG2MATCHATTVALUECASE (2)
 setFlag(1,1048576,1);  // CSEVALFLAG1XMLSPACEWARNING
You can pull those options out of the "if" statement and always execute the ones you want. A better way is to just set them in the Validator Engine Options under the various option pages (hopefully you can figure out what is what!), but you can override the options set in the Validator Engine Options with the setFlag() function in the start validation program.

By setting some options to be stricter, then you should be able to get more consistent results regardless of the DOCTYPE.
Image
Albert Wiersch

rag_gupta
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Tue Nov 30, 2010 10:17 pm
Contact:

Re: How to check html syntax using DocType:strict

Post by rag_gupta » Wed Jul 20, 2011 9:58 am

After changing the configuration, CSE is showing me error one by one and not all at once!
Pl. see the attmt.
Attachments
0029.jpg
0029.jpg (245.56 KiB) Viewed 11329 times

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3453
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: How to check html syntax using DocType:strict

Post by Albert Wiersch » Wed Jul 20, 2011 10:56 am

rag_gupta wrote:After changing the configuration, CSE is showing me error one by one and not all at once!
Pl. see the attmt.
Please enable the Message Window (View->Windows->Message) so you can see the full text of the messages. Some messages are displayed only once and will say so at the end. For example, the message in the screenshot should end in "This message is displayed only once.", so that is by design for that particular message.

The reason for that is that some people want to use that attribute ("target") anyway, because it still works, and don't want a bunch of those error messages as just one is more than enough to let them know about "target" not being valid.
Image
Albert Wiersch

rag_gupta
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Tue Nov 30, 2010 10:17 pm
Contact:

Re: How to check html syntax using DocType:strict

Post by rag_gupta » Fri Jul 22, 2011 4:09 am

With 180 flag enabled I'm not able to understand the reason of an error. I'm attaching the html file and the snapshot.

This code is present in this web page which when I validated with W3C validator gave this message:
This document was successfully checked as XHTML 1.0 Transitional!
Please note that the error is with doctype strict and the web page is doctype Transitional.
Attachments
error.zip
This is the html file for which cse is giving error with flag 180 set
(1.9 KiB) Downloaded 401 times
cse error message when checking above zip file
cse error message when checking above zip file
0022.jpg (364.47 KiB) Viewed 11213 times

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3453
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: How to check html syntax using DocType:strict

Post by Albert Wiersch » Fri Jul 22, 2011 8:39 am

rag_gupta wrote:With 180 flag enabled I'm not able to understand the reason of an error. I'm attaching the html file and the snapshot.
Thanks. I loaded error.html into CSE HTML Validator and reproduced the error message but there was a "?" at the end of the "</div>" on line 34 (which is not shown in the screenshot). If I remove the "?" then the error goes away. Typo?
Image
Albert Wiersch

rag_gupta
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Tue Nov 30, 2010 10:17 pm
Contact:

Re: How to check html syntax using DocType:strict

Post by rag_gupta » Fri Jul 22, 2011 1:27 pm

When I'm copy-pasting from cse to text editor then only this question mark(?) is appearing.
But when I checked the same content in the web page, CSE isn't complaining. Strange, I'll get back.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3453
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: How to check html syntax using DocType:strict

Post by Albert Wiersch » Fri Jul 22, 2011 2:45 pm

rag_gupta wrote:When I'm copy-pasting from cse to text editor then only this question mark(?) is appearing.
But when I checked the same content in the web page, CSE isn't complaining. Strange, I'll get back.
OK, please let me know what you find out, especially if you think the "?" is being added by some issue with CSE HTML Validator. Thank you.
Image
Albert Wiersch

Post Reply