XHTML Common Errors
WE ARE FAMILY :: IT World :: Programming
Page 1 of 1
XHTML Common Errors
Common errors
Some of the most common errors in the usage of XHTML are:
Failing to realize that documents won’t be treated as XHTML unless they are served with an appropriate XML MIME type
Not closing empty elements (elements without closing tags in HTML4)
Incorrect: <br>
Correct: <br />
Note that any of these are acceptable in XHTML: <br></br>, <br/> and <br />. Older HTML-only browsers interpreting it as HTML will generally accept <br> and <br />.
Not closing non-empty elements
Incorrect: <p>This is a paragraph.<p>This is another paragraph.
Correct: <p>This is a paragraph.</p><p>This is another paragraph.</p>
Improperly nesting elements (Note that this would also be invalid in HTML)
Incorrect: <em><strong>This is some text.</em></strong>
Correct: <em><strong>This is some text.</strong></em>
Not putting quotation marks around attribute values
Incorrect: <td rowspan=3>
Correct: <td rowspan="3">
Correct: <td rowspan='3'>
Using the ampersand character outside of entities
Incorrect: <title>Cars & Trucks</title>
Correct: <title>Cars & Trucks</title>
Using the ampersand outside of entities in URLs (Note that this would also be invalid in HTML)
Incorrect: <a href="index.php?page=news&style=5">News</a>
Correct: <a href="index.php?page=news&style=5">News</a>
Failing to recognize that XHTML elements and attributes are case sensitive
Incorrect: <BODY><P ID="ONE">The Best Page Ever</P></BODY>
Correct: <body><p id="ONE">The Best Page Ever</p></body>
Using attribute minimization
Incorrect: <textarea readonly>READ-ONLY</textarea>
Correct: <textarea readonly="readonly">READ-ONLY</textarea>
Mis-using CDATA, script-comments and xml-comments when embedding scripts and stylesheets.
This problem can be avoided altogether by putting all script and stylesheet information into separate files and referring to them as follows in the XHTML head element.
HTML Code:<link rel="stylesheet" href="/style/screen.css" type="text/css" />
<script type="text/javascript" src="/script/site.js"></script>Note: The format <script …></script>, rather than the more concise <script … />, is required for HTML compatibility when served as MIME type text/html.
If an author chooses to include script or style data inline within an XHTML document, different approaches are recommended depending whether the author intends to serve the page as application/xhtml+xml and target only fully conformant browsers, or serve the page as text/html and try to obtain usability in Internet Explorer 6 and other non-conformant browsers.
Some of the most common errors in the usage of XHTML are:
Failing to realize that documents won’t be treated as XHTML unless they are served with an appropriate XML MIME type
Not closing empty elements (elements without closing tags in HTML4)
Incorrect: <br>
Correct: <br />
Note that any of these are acceptable in XHTML: <br></br>, <br/> and <br />. Older HTML-only browsers interpreting it as HTML will generally accept <br> and <br />.
Not closing non-empty elements
Incorrect: <p>This is a paragraph.<p>This is another paragraph.
Correct: <p>This is a paragraph.</p><p>This is another paragraph.</p>
Improperly nesting elements (Note that this would also be invalid in HTML)
Incorrect: <em><strong>This is some text.</em></strong>
Correct: <em><strong>This is some text.</strong></em>
Not putting quotation marks around attribute values
Incorrect: <td rowspan=3>
Correct: <td rowspan="3">
Correct: <td rowspan='3'>
Using the ampersand character outside of entities
Incorrect: <title>Cars & Trucks</title>
Correct: <title>Cars & Trucks</title>
Using the ampersand outside of entities in URLs (Note that this would also be invalid in HTML)
Incorrect: <a href="index.php?page=news&style=5">News</a>
Correct: <a href="index.php?page=news&style=5">News</a>
Failing to recognize that XHTML elements and attributes are case sensitive
Incorrect: <BODY><P ID="ONE">The Best Page Ever</P></BODY>
Correct: <body><p id="ONE">The Best Page Ever</p></body>
Using attribute minimization
Incorrect: <textarea readonly>READ-ONLY</textarea>
Correct: <textarea readonly="readonly">READ-ONLY</textarea>
Mis-using CDATA, script-comments and xml-comments when embedding scripts and stylesheets.
This problem can be avoided altogether by putting all script and stylesheet information into separate files and referring to them as follows in the XHTML head element.
HTML Code:<link rel="stylesheet" href="/style/screen.css" type="text/css" />
<script type="text/javascript" src="/script/site.js"></script>Note: The format <script …></script>, rather than the more concise <script … />, is required for HTML compatibility when served as MIME type text/html.
If an author chooses to include script or style data inline within an XHTML document, different approaches are recommended depending whether the author intends to serve the page as application/xhtml+xml and target only fully conformant browsers, or serve the page as text/html and try to obtain usability in Internet Explorer 6 and other non-conformant browsers.
WE ARE FAMILY :: IT World :: Programming
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|