XHTML

XLXP Examples

XHTML Basic Example

XHTML Interview Questions And Answers

More interview questions and answers

What you understand about XHTML?

 XHTML stands for eXtensible HyperText Markup Language.It is more formal and more Hard and fast version of HTML.We can define XHTML with XML dtd which make easy to handle XHTML.

 Some information about XHTML are given below:
1.Target of XHTML is to replace HTML.
2.We can say that HTML4.01 and XHTML are almost same.
3.It is an more Hard and Fast version of HTML.
4.XHTML has a W3C recommendation.
5.We can say that XHTML is an Transition/combination of HTML and XML.
6.It has got official recommendation from W3C on 26th Jan 2000.
7.Using XHTML we can easily validate our document.

Why we use XHTML?

 We use XHTML because of some important reasons those are given below:

1.XHTML can run on all new browsers.
2.It is an combination of HTML and XML so,it support many important features of them.
3.XHTML also give us facility to write well formed document.
4.XHTML has facility to extend.We perform this task with use of extra modules to do things without pages.Where as this facility not provided by HTML.

 I have given you a HTML example in that example can on browsers successfully but it is not support all rules of HTML.

<html>
<head>
<title>This is wrong HTML code</title>
<body>
<h1>Wrong HTML code
</body>


 In above example both html and head tags are not close.According to HTML rule it should not run.But it run successfully.So, It is an example of wrong html code.

How XHTML is differ from HTML?

XHTML is an more formal,Hard and Fast version of HTML.Some main difference b/w XHTML and HTML are given below:

1.In XHTML element should be properly nested.
2.In XHTML when we started an element it must have closed tag.
3.XHTML support only lowercase element.
4.In an XHTML document one root element is necessary.

 But we can say that their is no much difference b/w HTML4.01 and XHTML.

Give an example shows properly nested element in XHTML?

 In HTML we can improperly nested some element each other like that,

<b><i>Gives text as bold and italic</b></i>

 Where as In XHTML, all elements must be properly nested within each other like that,

<b><i>Gives text as bold and italic</i></b>

 When you create nested lists keep one thing in mind list must be within <li> and </li> tags.

<ul>
  <li>Coca cola</li>
  <li>Pepsi
      <ul>
          <li>black</li>
          <li>blue</li>
      </ul>
  </li>
</ul>

Give example shows Element must be closed in XHTML?

 XHTML said an Empty and  Non-Empty Elements must be closed.

Example shows the case of Non-Empty Element.

<p>Write here paragraph</p>
<p>>Write here another paragraph</p>

Example shows the case of Empty Element.
1.Use to break <br />
2.Use to horizontal rule <hr />
3.<img src=\"r4r.gif\" alt=\"r4r logo\" />
 

Give example shows Element must be written in XHTML?

 In XHTML Your Element must be Written in Lower Case.

Example:
<body>
<p>Here write a paragraph</p>
</body>

Give example shows Document must have one root element in XHTML?

In XHTML all elements should be nested in the <html> root element.Elements inside the <html> root element can have their child or elements an so on.

 I have given you basic structure of XHTML document.

<html>
<head>Write here heading</head>
<body>Write here some code</body>
</html>

What are the rule essential for XHTML Syntax?

 I have given you rules keep in mind when you want to create an XHTML document.

Rule1:Write attribute names only in lower case letters.
Rule2:Assigned attribute values must be quoted.
Rule3:Attribute minimization must be prohibited.
Rule4:In XHTML name attribute is replaced by id attribute.
Rule5:In XHTML DTD must set mandatory elements.

Example of Rule1:Write attribute names only in lower case letters.
<table width=\"200%\">
Example of Rule2:Assigned attribute values must be quoted.

<table width=\"100%\">
Example of Rule3:Attribute minimization must be prohibited.
<input checked=\"checked\" />
<input readonly=\"readonly\" />
<input disabled=\"disabled\" />
<option selected=\"selected\" />
<frame noresize=\"noresize\" />


Example of Rule4:In XHTML id attribute is replaced by name attribute.

HTML 4.01 defines a name attribute for the elements a, applet, frame, iframe, img, and map.

<img src=\"r4r.gif\" id=\"r4r\" />

 I have add a extra space before \'/\' to make our XHTML document with current browsers.
Using lang attribute we can specify the language of content.

<div lang=\"no\" xml:lang=\"no\">Arial</div>
Example of Rule5:In XHTML DTD must set mandatory elements.
 DOCTYPE declaration is essential for each XHTML document. The html, head and body elements must be present.Write title element inside the head.

<!DOCTYPE Doctype write here>
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>Write here title</title>
</head>
<body>
</body>
</html> 
DOCTYPE declaration is not an XHTML element.So, Their is no need to closed DOCTYPE declaration.

How you define DTD in XHTML?

 Before I given use of DTD. I want to remember what is DTD.

DTD: Its stand for Document Type Declaration. It specify the syntax of web page in SGML. We use DTD on SGML applications like: HTML,XML etc.In XHTML we can say that DTD is an computer readable language which is used to allow syntax of XHTML.

 In XHTML we use These three DTD\'s,
1.STRICT
2.TRANSITIONAL
3.FRAMESET

1.Strict DTD: We use strict DOCTYPE if we want really clean markup, free of presentational clutter.And also use together with CSS.

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

2.Transitional DTD: We use transitional DOCTYPE if we want to still use HTML\'s presentational features.

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

3.Frameset DTD:We use frameset DOCTYPE if we want to use HTML Frames to split our web page into two or more frames.
<!DOCTYPE html  PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">

How to print \"Hello World!\" using XHTML?

 To print \"Hello World!\" you have to write following code.

<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xml:lang=\"en\" lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>Hello World!</title>
</head>
<body>
<p>This is first XHTML coded web page.</p>
</body>
</html>
</p>

How you use img and hr tag in XHTML because both tags doesn\'t have closed tag?

 I have given you solution of how to use img and hr tag in XHTML.Now,the solution for given problem is that,Add only hte forward slash in element.

<img src=\"r4r.gif\" />

Write text <hr />

 Keep in mind when use forward slash you should add an extra slash before forward slash.

Why their is a need of modular DTDs in XHTML?

  Using modularity it easier to deploy new developments. An application may wish to support only a subset of XHTML. For example a mobile phone, an Internet TV or even a Web-aware cooker may only require a subset of XHTML.

How you perform validation in XHTML?

 We can Validate our XHTML document by using W3C\'s validator.
 Here, I given you example which is validate our XHTML document with DTD.

Example In which I validate our XHTML document using strict DTD.

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html>
<head>
<title>title of the document</title>
</head>
<body>
<p>Here write a paragraph</p>
</body>
</html>

What assumption that we use with XHTML?

What are the advantages of XHTML?

 Some main advantage of XHTML are given below:

1.In XHTML we can use mixed namespaces.
2.work on XHTML is much simple than HTML.
3.When your document is not well formed than it will immediately informed to you due to an error from your UA in XHTML.

Tell me how to convert an HTML page into XHTML?

If we want to convert HTML pages into XHTML than you have to insert some lines at the starting of document.
 
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">

Write example that shows every attribute must have a value in XHTML?

 Using example I will show you in XHTML every attribute must have a value.

Example in HTML:


<ol compact>
<input type=\"radio\" name=\"title\" value=\"decline\" checked>decline</input>

 Below, I write a same example in XHTML.

<ol compact=\"compact\" >
<input type=\"radio\" name=\"title\" value=\"decline\" checked=\"checked\">decline</input>

 In this we assign value compact, checked to element compact and checked.

In XHTML tags may overlap or not?

 In XHTML tags may not be overlapped.

Example:
<em> emphasized text and <b>bold </em>text</b>
 We can use above example in XHTML like that,

<em>emphasized text </em> is <b>bold text</b>

Is is right only certain tags may nest inside other tags in XHTML?

 Yes, In XHTML we can insert only certain tags inside other tags.

Example:
<ol>
Some my favorite flowers are:
<li>lotus</li>
<li>lilly</li>
<li>sunflower</li>

and my most favorite flower is:
<li>red rose</li>
</ol>

In the above example we insert the paragraph between <li> tag.It\'s wrong.
 In case of XHTML our example looks like that, becomes

<p>Some my favorite flowers are:</p>
<ol>
<li>lotus</li>
<li>lilly</li>
<li>sunflower</li>
<li>red rose</li>
</ol>

XHTML Interview Questions And Answers