two validations in HTML page.

Dear Experts,

What will happen if I'll make two validations in my HTML page like these?

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


Thanks,

Jimi J
JaimeJegoniaAsked:
Who is Participating?
 
AGBrownCommented:
I'll assume you are, and that you are using C# and Visual Studio. I have tested this, and it works.

Open your aspx, and put the following definition at the top of the markup, in place of your DOCTYPE:
<asp:literal id="ltDocType" runat="server"></asp:literal>

Then put the following in your Page_Load:
            private void Page_Load(object sender, System.EventArgs e)
            {
                  if (!IsPostBack)
                  {
                        switch (Request.UserAgent)
                        {
                              case "FirefoxUserAgent":
                                    this.ltDocType.Text = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Strict//EN\" >";
                                    break;
                              default:
                                    this.ltDocType.Text = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" >";
                                    break;
                        }
                  }
0
 
123654789987Commented:
0
 
JaimeJegoniaAuthor Commented:
May be you are right but it was not clearly stated. However my real interest is, am I getting the two standards or the 1st one is overwritten by the the second one? In effect, I'm getting only the second one.

One of the concerned also is, it slow me down a little because I'm checking with the 2 sites on page loading.

Any idea?

Thanks.

 
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
AGBrownCommented:
The problem is more whether or not the two definitions are complimentary. AS I understand it, and please correct me if I get this wrong:
- XHTML 1.0 transitional is a tighter version of HTML 4, so you can be XHTML 1.0 transitional AND Html 4.0 if you are XHTML 1.0 transitional.
- But, if you are HTML 4 you are not necessarily XHTML 1.0 transitional.

Is there a reason you want to use both? XHTML 1.0 sort of implies HTML 4.

Andy
0
 
AGBrownCommented:
PS I'm pretty certain you can't have two DOCTYPE declarations. I can't find anything saying that you "can't", but more importantly there is nothing saying that you "can" either. That msdn link doesn't specify that you can, it just puts two next to each other as examples of what you can use

As an experiment, I pulled the html for an XHTML page from my site, and put two doc type declarations at the top:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!doctype html public "-//w3c//dtd html 4.01 transitional//en"
   "http://www.w3.org/tr/html4/loose.dtd">

I then passed it through the w3.org validator (http://validator.w3.org/) and it failed, where previously it passed. I think the reason is that once you pass the first DOCTYPE line, you are assumed to have started your document proper, and the schema specified by the DOCTYPE does not include DOCTYPE.

I'm stabbing in the dark a bit here, but it seems to all make sense. I have looked, and I just can't find anything to confirm this though. The best I can find is the original DOCTYPE definition in Html 3.2 (http://www.w3.org/TR/REC-html32.html) which says "Documents start with a <!DOCTYPE> declaration followed by an HTML element containing a HEAD and then a BODY element:". This would seem to imply that HTML documents according to that specification only have one DOCTYPE. If you look at the HTML 4.01 specification, then it also always mentions DOCTYPE in the singular (http://www.w3.org/TR/html4/struct/global.html).

Curioser and curioser. If I had to commit to an answer, I would say you are only allowed one DOCTYPE, as it doesn't make sense to have two. I wait to be proved wrong ...

Andy
0
 
JaimeJegoniaAuthor Commented:
Andy,

I am also about 95 convince that we can't make 2 DOCTYPE declarations. I am only tempted to use it for some display instances between IE and Firefox and I thought doing it would solve the issue. Anyway, thank you very for pulling lot of information for me. I'll just wait for sometime until we get certain of what we are trying to prove.


Thanks.  

0
 
AGBrownCommented:
I checked with a colleague, between us we are 99.999999% sure you can't have two.

Are you sending out aspx pages? There is probably a way of changing the header based on the User Agent part of the request headers.

Andy
0
 
JaimeJegoniaAuthor Commented:
Andy,

If you can a way of changing the header based on the User Agent part of the request headers, I will appreciate it.  If you can indicate some possibilty, instead of opening another issue, I will just increase the points of this question.

Thanks.
0
 
AGBrownCommented:
Are you using asp.net? Which version?
0
 
JaimeJegoniaAuthor Commented:
I am using ASP.Net 2.0 C# language.
0
 
AGBrownCommented:
Lol, posted that just as you did - that was a good guess!
0
 
JaimeJegoniaAuthor Commented:

Andy,

It seems to be working but I have a problem how to include the http, because i want to switch between DOCTYPE in my original question:

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

How can I do it.

Thanks.
0
 
AGBrownCommented:
what is the problem you are getting? Is it a compilation problem? Make sure you delimit any occurences of " that are in the string with a \, so you have:

                         case "FirefoxUserAgent":
                              this.ltDocType.Text = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
                              break;
0
 
JaimeJegoniaAuthor Commented:
I'am always getting the default, may be the "FirefoxUserAgent" is not right.  What's the IE user agent?
0
 
AGBrownCommented:
Ok, sorry, I didn't know that - I just wacked that in. You need to look up the different user agents on google. There are lots of pages that list them, like http://www.psychedelix.com/cgi-bin/free-search.cgi?template=free-search-detail.html&dbname=allagents.csv&key2=id_m_989&action=searchdbdisplay. Because of the variable nature of the useragents, you might need to find a site that shows you how to do a comparison to get the key parts out of it. If you have to do that then you won't be able to use switch like that, you'll have to write a function that returns a user agent type, maybe

enum UserAgentEnum
{
FireFox,
IE,
Other
}

public UserAgentEnum GetUserAgent()
{
if (<pseudocode> MatchesFireFoxStrings)
   return UserAgentEnum.Firefox
else if (<pseudocode> MatchesIEStrings)
   return UserAgentEnum.IE
else
   return UserAgentEnum.Other
}

then the switch would be:

switch (this.GetUserAgent())
{
case UserAgentEnum.Firefox:
    // do firefoc doctype
    break;
...
...
...
}
}


Alternatively, run your code in debug mode from IE and firefox, and pick up the value of the Request.UserAgent and use that for the switch, in the short term.
0
 
JaimeJegoniaAuthor Commented:
Andy,

These what I've got:

MSIE 6.0
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

Firefox
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1


This is what I did to make it work, at least:

 if (!this.IsPostBack)
        {        
          if ((Request.UserAgent.IndexOf("MSIE 6.0") > -1)||(Request.UserAgent.IndexOf("MSIE 5.5") > -1) )
               {
                 this.ltDocType.Text = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
               
               }
          else
               {
                 this.ltDocType.Text = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Strict//EN\" >";
               }        
}

I'm closing this request already and opening another request how to verify what present on that Request.UserAgent using split()

Thank you very much time and efforts.



Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.