[ZT] Web Standard and ASP. NET-Part1 XHTML Quick Start

Source: Internet
Author: User
Tags closing tag

Web Standard and ASP. NET-Part1 XHTML Quick Start

Dflying | 26 March, 2006

Web Standard is more and more important in current web based application development. in these series of posts I am going to sharing some of my ideas about how to build Web Standard applications using ASP. NET 2.0.

This post is the first in these series. It introduces some basic XHTML concepts and a quick guide for HTML developers to get familiar with XHTML.

The famous HTML markup language is officially outdated now while the replacement and successor is XHTML (http://www.w3.org/MarkUp ). if you write Web pages with the stricter rules of XHTML, your Web pages will work consistently with current browsers, and you can perform CT they will continue to work with new versions of current browsers in the future. you will also get more cross-browser, cross-device, and cross-operating system compatible.

XHTML has two major goals:

  • Separate document structure (using XHTML markup) and presentation (using CSS ).
  • Reformulate HTML as an application of XML.

For the first goal, W3C removed some HTML tags and attributes such as <font> and bgcolor, for these kinds of tags/attributes have nothing to do with the document structure and shoshould be defined in CSS. also, particle tags shoshould not be assumed as having particle appearance. e. g.

For the second goal, XHTML is to enforce the stricter rules of XML on HTML developers. XHTML 1.0 is a reformulation of HTML 4.01 as an XML 1.0 application (http://www.w3.org/MarkUp ). in other words, when you build an XHTML Web page using, you are actually creating an XML document. an XML document has a much stricter syntax than HTML document which will be discussed later.

Also XHTML has three versions:

  • XHTML 1.0 Transitional
  • XHTML 1.0 Strict
  • XHTML 1.0 Frameset

XHTML 1.0 Transitional contains all of the tags and attributes from HTML 4.01 Transitional. The XHTML 1.0 Transitional standard was introduced to enable existing HTML designers and developers to migrate to XHTML easily.

XHTML 1.0 Strict differs from XHTML 1.0 Transitional by enforcing a cleaner separation between document structure and presentation which requires you using CSS to control the page appearances.

XHTML 1.0 Frameset documents are intended to be documents that use<Frameset>Tag to partition a browser into multiple frames (XHTML 1.0 Transitional and Strict pages cannot contain<Frameset>Tags ).

Hmmm, okay for these. I am not going to explain the whole things of XHTML and of course you may find other resources and details by Google or MSN Search, or just by leaving a comment here. in the following section I want to show some basic rules of writing XHTML pages.

An XHTML page must be a well-formed and valid XML document which is much stricter than HTML. the differences between HTML and XHTML are summarized in Section 4 of the XHTML 1.0 recommendation. here's a list of the most important issues for building a valid XHTML page:

  1. The page must include a valid xhtml doctype.

A valid XHTML page must include an xhtml doctype before any of its content. when you create a new ASP. NET page in Visual Studio 2005 or Microsoft Visual Web Developer, the correct DOCTYPE for XHTML 1.0 Transitional is automatically inserted in the page. here are the four standard xhtml doctypes:

XHTML 1.0 Transitional

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

XHTML 1.0 Strict

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

XHTML 1.0 Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

XHTML 1, 1.1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

Adding a DOCTYPE to a page has an impact on how the page is rendered in a browser. To be discussed later.

  1. The root element must refer to the XHTML namespace

The opening<Html>Tag of an XHTML page must specify a default namespace of http://www.w3.org/1999/xhtml. E. g. an XHTML 1.0 Transitional page.


 
  1. All element and attribute names must be lowercase.

XML is case-sensitive. So, there is a difference between<P>Tag and<P>Tag. Only<P>Is a valid XHTML paragraph tag.

  1. Attribute values must always be quoted.

Always wrap attribute values in either double or single quotation marks. E. g., the following is invalid XHTML.

<a href=SomePage.aspx>Next</a>

In this case, the href attribute is missing quotation marks. The following is valid XHTML.

<a href="SomePage.aspx">Next</a> 

You can configure Visual Studio 2005 and Visual Web Developer to automatically quote attribute values, by selecting the menu optionTools,Options,Format.

  1. All non-empty elements that have an opening tag must have a matching closing tag.

If you have an opening<P>Tag, then you must include a closing</P>Tag to mark the end of the paragraph. In the case of tags that never contain any content, such as<Br>Tag, you can either supply a both an opening and closing<Br> </Br>Tag, or you can use the empty element shorthand<Br/>.

In order to make your XHTML pages backward-compatible with existing HTML browsers, you need to be careful about how you open and close your tags. for example, existing HTML browsers tend to misinterpret an opening and closing<Br> </Br>Tag as two<Br>Elements. For that reason, you should use the empty element shorthand<Br/>.

Furthermore, existing HTML browsers have problems with the empty element shorthand<BR/>Unless you are careful to add a space before the closing slash. So, you shoshould Add<BR>Element to a page using<BR [space]/>And not<BR/>.

  1. There must be no overlapping tags.

You can nest tags, but you are not allowed to overlap tags. For example, the following XHTML is valid.

<b><i>This is bold and italic</i></b>

However, the following XHTML is invalid.

<i><b>This is bold and italic</i></b>
  1. There must be no attribute minimization.

All attributes must have a value, even when it looks a little strange. For example, the tag<Input type = "checkbox" checked/>Is invalid XHTML, becauseCheckedAttribute does not have a value. The tag shocould be written<Input type = "checkbox" Checked = "checked"/>.

  1. The id attribute must be used instead of the name attribute.

In HTML, you useNameAttribute to identify<A>,<Applet>,<Form>,<Frame>,<IFRAME>,<IMG>, And<Map>Elements. While you can useNameAttribute when building XHTML 1.0 transitional pages,NameAttribute has been removed from the XHTML 1.0 strict and XHTML 1.1 standards. You shoshould useIdAttribute to identify these elements instead.

  1. The contents<Script>And<Style>Elements must be wrapped in CDATA sections.

If you use special characters such as <or &, or entity references such& Lt;Or& Amp;In a script or style sheet, then you'll need to mark the contents of your script or style sheet as a CDATA (character data) section, as follows.

<script type="text/javascript"><![CDATA[ function isLess(a, b) {  if (a < b)    return true;} ]]></script>

Notice that the JavaScript function contained in the script between des a <character. if you do not wrap the script in a CDATA section, then the <character wocould be interpreted as marking the start of an XHTML tag.

Using a CDATA section will not work with all browsers. For example, Internet Explorer considers a CDATA section in<Script>Tag a syntax error. You can avoid this problem by adding JavaScript comments, as follows.

<script type="text/javascript">/* <![CDATA[ */ function isLess(a, b) {  if (a < b)    return true;} /* ]]> */</script>

JavaScript uses/*And*/To mark the beginning and end of a comment. therefore, the CDATA section is den from the JavaScript, but not from the browser that parses the page. in general, it is a better idea to place your style rules and scripts in external files and reference the files from your XHTML pages. using external style sheets and scripts enables you to avoid all of these issues.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.