xhtml Flashcards

1
Q

You are asked to convert an existing HTML web page into XHTML. Check the following code snippet and comment on what needs to be changed.
‹b›‹i›Sub-sub-section heading‹/b›‹/i›

A

The code is invalid for XHTML because the nesting of the opening and closing tags is incorrect. The correct XHTML would be: ‹b›‹i›Sub-sub-section heading‹/i›‹/b›

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
A common problem in HTML to XHTML is proper coding of ordered lists. Check the syntax of the following XHTML code snippet and comment on its validity as HTML and XHTML.
‹ol›
    ‹li›
        ‹ol›
            ‹li›‹/li›
        ‹/ol›
    ‹li›‹/li›
‹/ol›
A

This code would parse and display as HTML, but is invalid XHTML because the first ‹li› does not have a matching closing ‹/li› tag.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

XHTML was designed to solve some problems with HTML, and XHTML code needs to be well-formed. What does this mean?

A

Modern HTML and SGML browsers often overlook mistakes in HTML code. However, this creates problems in code maintainability. Well-formed XHTML code requires that an XML parser be able to parse HTML code, thus all tags must be properly structured, coded, and nested in XHTML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The following code runs well on an HTML browser, but gives an error on an XHTML-compliant browser. How would you fix this?
‹img src=”interview.gif” alt=”Interview”›

A

By adding a self-closing tag: ‹img src=”interview.gif” alt=”Interview” /›

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A web page has been recently modified to XHTML but shows errors when validated by the W3C Validator. The lines of code reported are shown below. Re-write them as necessary to parse as valid XHTML.
Lorem Ipsum‹hr›
Duis vel augue felis, vitae elementum nibh.‹br› Etiam at dolor dolor.‹br›

A

Lorem Ipsum‹hr /›

Duis vel augue felis, vitae elementum nibh.‹br /› Etiam at dolor dolor.‹br /›

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain why the following XHTML code snippet will display correctly in a web browser but give errors in an XHTML parser.
‹BODY›
Other XHTML elements here
‹/BODY›

A

The code uses tag names in uppercase, which is invalid XHTML syntax. The correct way to write this would be
‹body›
Other XHTML elements here
‹/body›

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The following code snippet is in HTML and you are asked to re-write it in XHTML. Before re-writing it, comment on the difference in syntax between HTML and XHTML for this snippet.
‹h1›Etiam at dolor dolor.‹/h1›
‹p›Nam ante augue, posuere nec imperdiet vitae, volutpat at arcu.‹/P›
‹p›Duis vel augue felis, vitae elementum nibh.‹/p›

A

Things to check are proper nesting of the tags, and also that they are in the proper case. In this case, one element is not. The correct XHTML is
‹h1›Etiam at dolor dolor.‹/h1›
‹p›Nam ante augue, posuere nec imperdiet vitae, volutpat at arcu.‹/p› ‹p›Duis vel augue felis, vitae elementum nibh.‹/p›

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

An HTML page is first converted into XHTML and then opened in an XML parser. The code for the page is given below. Comment on possible problems of opening the page in the parser.
‹!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”›
‹html›
‹head›‹title›Posuere nec imperdiet vitae‹/title›‹/head›
‹body›
‹h1›‹i›Posuere nec imperdiet vitae‹/h1›
‹p›Duis vel augue ‹i›felis‹/i›, at ‹b›dolor dolor, vitae elementum nibh‹/p›
‹/body›
‹/html›

A

XHTML is valid XML and will parse on an XML parser if it is correctly coded. The main problem that will be encountered is improper nesting of tags. For instance, the first ‹i› is not closed. Also, the ‹b› in the paragraph is not closed also. Once these are fixed, the document will show up as an XML tree on the parser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The W3C specification of XHTML contains sets of modules that allow interoperability on mobile devices. Comment on whether the following XHTML code for a list module is valid.
‹dl›
‹di›
‹dt›Life‹/dt›
‹dd›Currently, scientists do not have a ‹em›precise‹/em› definition of life‹/dd›
‹/di›
‹/dl›

A

This is valid XHTML because all tags are in proper case and properly nested. The ‹dl› tag stands for definition lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

XHTML Basic is a subset of XHTML for mobile devices. Will the following code snippet be supported on a mobile browser that runs XHTML Basic?
Greetings, please click ‹a href=”somepage.html”›here to ‹/a›proceed

A

Yes, because ‹a› is part of the XHTML Basic modules, and this is valid XHTML code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Inspect the following HTML code snippet and comment on how to make it valid XHTML by adding additional required elements, attributes, or syntax adjustments needed.
‹html›
    ‹head›
        ‹title›Title here‹/title›
    ‹/head›
    ‹body›
        ‹h1›Header here‹/h1›
        ‹p›Text here‹/p›
    ‹/body›
    ‹/html›
A

The only element needed here is the !DOCTYPE definition for this page, before the ‹html› tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In XHTML, certain elements are mandatory on a standard web page. List these elements by providing the skeleton markup of a valid, empty XHTML standard page.

A

‹!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”›
‹html› ‹head›‹/head› ‹body›‹/body› ‹/html›

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The code below is taken from an HTML web page that will not parse on an XHTML web browser. What is the cause of the problem and what are possible fixes?
‹!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Loose//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-loose.dtd”›
‹html›
‹head›‹/head›
‹body›‹/body›
‹/html›

A

The problem is in the !DOCTYPE definition. Loose is not a valid type, and should be replaced with Transitional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The Document Type Definition (DTD) specifies the syntax of a web page in SGML. There are three !DOCTYPE definitions in the DTD specifications. List these.

A

Strict, Transitional, Frameset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The following XHTML code snippet is defined in the !DOCTYPE definition as Transitional. Comment on whether it is valid or not.
‹body bgcolor=”red” text=”blue”›
‹p›Text here‹/p›
‹/body›

A

This is valid because the Transitional type allows attributes to be added to support older browsers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

An XHTML web page is defined as Strict in the !DOCTYPE definition. Will the following code parse correctly?
‹body bgcolor=”red”›
‹h1›Title here‹/h1›
‹/body›

A

The Strict type is very restricted and is meant to separate all presentation elements from content. Therefore, no formatting with XHTML is allowed, and instead CSS needs to be used for all settings about presentation. In that case, the code will be incorrect because of the bgcolor attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

There are three types of DTDs available in XHTML. Among these, Strict is the most restrictive, as its name implies. Comment on the pros and cons of Strict XHTML documents.

A

This DTD allows the markup to be free of presentation details, making maintainability easier. However, this imposes a very restrictive set of code in which no attributes can be used for formatting, only CSS. Some browsers may not render Strict pages as a result.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Frames are special forms of web pages, and XHTML makes provision for these. What DTD is used to define a web page containing frames?

A

Frameset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

A web page is defined with the Frameset !DOCTYPE definition. Will the following code snippet be valid?
‹iframe src=”somepage.html”›‹/iframe›

A

This will not be valid, because only the ‹frameset› and ‹frame› tags are valid for the Frameset DTD.

20
Q

Recently, a new acronym has surfaced in the web development area, SGML. Are you aware of this acronym, and what does it stand for?

A

Standard Generalized Markup Language, which is a specification for what elements, characters, attributes can appear within a specific type of document.

21
Q

HTML 4 allows attribute minimization within its elements, while XHTML does not allow this feature. A typical example of attribute minimization is in the use of check box ‹input› tags. Provide a code snippet to demonstrate this.

A

‹input checked› is an example of attribute minimization, while the proper XHTML is ‹input checked=”checked” /›

22
Q

he following code may be using attribute minimization. Will this be valid XHTML code? Give your reasoning.
‹frame noresize /›

A

This code is using attribute minimization and is invalid XHTML because the XHTML specification requires all attribute values to be enclosed in single or double quotes: ‹frame noresize=”noresize” /›

23
Q

The following code snippet is deemed invalid XHTML after testing by your test team. The !DOCTYPE for this web page is Transitional. How will you fix it?
‹table width=100% /›

A

‹table width=”100%” /›

24
Q

A web page contains the following HTML code. How will you convert this code into valid XHTML?
‹input TYPE=checkbox disabled›

A

Conversion of all tags and attributes to lowercase, followed by quoting all attribute values, and finally ensuring all tags are properly closed.
‹input type=”checkbox” disabled=”disabled” /›

25
Q

A web page’s content is shown as one continuous block of text without any spacing between paragraphs. List two XHTML elements that you can use to create space between paragraphs?

A

‹p›‹/p›, ‹br /›

26
Q

The following text is from a client’s XHTML web page.
Phasellus molestie ornare fringilla.
Aenean a felis ligula.
Duis sem dolor, commodo nec volutpat ut, accumsan eu leo.
Praesent vulputate venenatis eros, sed consectetur sapien luctus at.
How would you add a horizontal line between the first sentence and the remaining lines?

A

Phasellus molestie ornare fringilla.‹hr /›

27
Q

In a paragraph, sections of the text need to be given a different font size than the rest of the text. What XHTML element would you use to wrap these sections to apply the required styling?

A

‹span›‹/span›

28
Q

On a programming website, the author wishes to show XHTML codes as examples. What XHTML element is best for wrapping these code samples?

A

‹code›‹/code›

29
Q

Your client wishes that you control which element gets focus when the TAB key is pressed on a web page. What XHTML attribute would you use to control this?

A

tabindex
‹a href=”http://www.w3schools.com/” tabindex=”2”›W3Schools‹/a›‹br /›
‹a href=”http://www.google.com/” tabindex=”1”›Google‹/a›‹br /›
‹a href=”http://www.microsoft.com/” tabindex=”3”›Microsoft‹/a›

30
Q

You are asked to build a list that contains an item and its description. A definition
list is perfectly suited for this type of data. Provide the basic XHTML code for a definition list.

A

‹dl›

‹dt›Item‹/dt› ‹dd›Description‹/dd› ‹/dl›

31
Q

An XHTML web page is defined as Transitional DTD. What XHTML element is best suited to show other web page documents within this web page.

A

‹iframe›‹/iframe›

32
Q

On a web page, a page is expected to load in an ‹iframe› element when the link to a page called “otherpage.html” is clicked. Write an XHTML snippet code of this.

A

‹a href=”otherpage.html” target=”frameid”›Open Other Page‹/a›
‹iframe id=”frameid” src=”index.html”›‹/iframe›

33
Q

An XHTML web page is of Frameset DTD. Give a skeleton code of how you would create the following layout: banner on top of page, followed 2 columns below it, left column for navigating, right column for content.

A

‹frameset rows=”, ” cols=”“› ‹frame src=”banner.html” /› ‹frameset cols=”, *“›
‹frame src=”left.html” /›
‹frame src=”right.html” /› ‹/frameset›
‹/frameset›

34
Q
An XHTML document defined as Frameset DTD is failing to display on all browsers tested on. Inspect the following code and comment on any errors that will help show the page correctly.
‹html›
    ‹head›
        ‹title›Title‹/title›
    ‹/head›
    ‹body›
        ‹frameset rows="*, *" cols="*"›
            ‹frame src="page1.html" /›
            ‹frame src="page2.html" /›
        ‹/frameset›
    ‹/body›
‹/html›
A

The ‹body› tag is invalid when the document is defined as Frameset. Once the ‹body› tags are removed, the page will show correctly.

35
Q

Is the following code valid for aligning a ‹div› element to the right of the screen for an XHTML web page defined as Transitional DTD?
‹div align=”right”›‹/div›

A

Yes, this is valid for Transitional DTD.

IT IS INVALID IN HTML5

36
Q

On a web page for a kids website, a ‹table› used needs to be colored white. Given that the page is XHTML Strict, comment on the following code snippet.
‹table bgcolor=”white”›‹tr›‹td›Other code‹/td›‹/tr›‹/table›

A

This would be invalid XHTML because bgcolor is not permitted with Strict DTD.

37
Q

What is the value of the type attribute of the ‹input› element that would allow files to be uploaded?

A

‹input type=”file” /›

38
Q

A button needs to be designed on a web page so that part of it has an image showing. What XHTML element is best suited for this?

A

‹button› elements can contain XHTML code within the start and close tags, so an ‹image› can be placed within it, for example, ‹button›‹img src=”img.jpg” /› Text‹/button›

39
Q

How can a form be redirected to another page after the submit button has been clicked? Provide an XHTML code snippet that is DTD Strict.

A

form action=”nextpage.html”›‹/form›

40
Q

When a large amount of text data needs to be entered into a form, including possible line breaks, what XHTML form element would be best suited for this size and type of data?

A

‹textarea›‹/textarea›

41
Q

On a registration form, there needs to be a selection for Gender, with two options: Man, Woman. Only one of these options can be selected. Provide an XHTML code snippet of the XHTML to achieve this that is of type Strict DTD.

A

‹input type=”radio” name=”gender” value=”Man” /›

‹input type=”radio” name=”gender” value=”Woman” /›

42
Q

A form needs to redirect to a new page that should also open in a new window. Provide a valid XHTML code snippet of what attribute can be used to achieve this. Assume that the web page is DTD Transitional.

A

‹form action=”nextpage.html” target=”_blank”›‹/form

43
Q

A web page is defined as XHTML DTD Strict, and causes an error. Inspect the following code segment and determine what the cause of the error is?
‹form target=”_top”›‹/form

A

The target attribute is invalid in DTD Strict. Removing it will fix the error

44
Q

Forms can be used to send data such as files to the host server of a web page. Is it possible to specify the type of files that are allowed using XHTML only?

A

Yes, by setting the file types in the accept attribute of the form
form action=”form_action.asp” accept=”image/gif,image/jpeg”

45
Q

You come across XHTML code in which 2 forms were needed for submitting different data, but the forms are nested within each other as shown below. Comment on the functionality of these forms.
‹form›
‹form›‹/form›
‹/form›

A

The internal form will not behave as an independent form, as the browser will recognize only the top ‹form› due to the nesting.

46
Q

There are parts of a long registration form on a website that need to be logically grouped. What XHTML element is recommended for this kind of grouping?

A

The ‹fieldset› XHTML element is best suited for this task.