?
Solved

two validations in HTML page.

Posted on 2006-03-20
16
Medium Priority
?
237 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:JaimeJegonia
  • 8
  • 7
16 Comments
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 100 total points
ID: 16244391
0
 

Author Comment

by:JaimeJegonia
ID: 16244760
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
 
LVL 12

Expert Comment

by:AGBrown
ID: 16248121
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:AGBrown
ID: 16248347
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
 

Author Comment

by:JaimeJegonia
ID: 16253514
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
 
LVL 12

Expert Comment

by:AGBrown
ID: 16256214
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
 

Author Comment

by:JaimeJegonia
ID: 16256386
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
 
LVL 12

Expert Comment

by:AGBrown
ID: 16256402
Are you using asp.net? Which version?
0
 

Author Comment

by:JaimeJegonia
ID: 16256437
I am using ASP.Net 2.0 C# language.
0
 
LVL 12

Accepted Solution

by:
AGBrown earned 1200 total points
ID: 16256443
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
 
LVL 12

Expert Comment

by:AGBrown
ID: 16256446
Lol, posted that just as you did - that was a good guess!
0
 

Author Comment

by:JaimeJegonia
ID: 16256703

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
 
LVL 12

Expert Comment

by:AGBrown
ID: 16256721
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
 

Author Comment

by:JaimeJegonia
ID: 16256855
I'am always getting the default, may be the "FirefoxUserAgent" is not right.  What's the IE user agent?
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16256971
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
 

Author Comment

by:JaimeJegonia
ID: 16257889
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question