Section F.8. Special Characters and More Line Breaks


F.8. Special Characters and More Line Breaks

When marking up text, certain characters or symbols (e.g., <) may be difficult to embed directly into an XHTML document. Some keyboards do not provide these symbols, or the presence of these symbols may cause syntax errors. For example, the markup

 <p>if x < 10 then increment x by 1 </p> 


results in a syntax error because it uses the less-than character (<), which is reserved for start tags and end tags such as <p> and </p>. XHTML provides character entity references (in the form &code;) for representing special characters. We could correct the previous line by writing

 <p>if x &lt; 10 then increment x by 1</p> 


which uses the character entity reference &lt; for the less-than symbol.

Figure F.9 demonstrates how to use special characters in an XHTML document. For a list of special characters, see Appendix H, XHTML Special Characters.

Figure F.9. Special characters in XHTML.

  1  <?xml version = "1.0" ?>  2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  3     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  4  5  <!-- Fig. F.9: contact2.html      -->  6  <!-- Inserting special characters -->  7  8  <html xmlns = "http://www.w3.org/1999/xhtml">  9     <head> 10        <title>Internet and WWW How to Program - Contact Page 11        </title> 12     </head> 13 14     <body> 15 16        <!-- special characters are entered --> 17        <!-- using the form &code;      --> 18        <p> 19           Click 20           <a href = "mailto:deitel@deitel.com"> here </a> 21           to open an e-mail message addressed to 22           deitel@deitel.com. 23        </p> 24 25        <hr /> <!-- inserts a horizontal rule -->                26 27        <p>All information on this site is <strong>©</strong>    28           Deitel <strong>& </strong> Associates, Inc. 2004.</p> 29 30        <!-- to strike through text use <del> tags   --> 31        <!-- to subscript text use <sub> tags        --> 32        <!-- to superscript text use <sup> tags      --> 33        <!-- these tags are nested inside other tags --> 34        <p><del>You may download 3.14 x 10 <sup>2 </sup>            35           characters worth of information from this site.</del>    36           Only <sub> one</sub> download per hour is permitted.</p> 37 38        <p>Note: <strong>< &frac14; </strong> of the information 39           presented here is updated daily. </p>                 40 41     </body> 42  </html> 

Lines 2728 contain other special characters, which can be expressed as either character entity references (i.e., word abbreviations such as amp for ampersand and copy for copyright) or numeric character referencesdecimal or hexadecimal (hex) values representing special characters. For example, the & character is represented in decimal and hexadecimal notation as &#38; and &#x26;, respectively. Hexadecimal numbers are base 16 numbersdigits in a hexadecimal number have values from 0 to 15 (a total of 16 different values). The letters AF represent the hexadecimal digits corresponding to decimal values 1015. Thus in hexadecimal notation we can have numbers like 876 consisting solely of decimal-like digits, numbers like DA19F consisting of digits and letters and numbers like DCB consisting solely of letters. We discuss hexadecimal numbers in detail in Appendix B, Number Systems.

In lines 3436, we introduce three new elements. Most browsers render the del element as strike-through text. With this format users can easily indicate document revisions. To superscript text (i.e., raise text on a line with a decreased font size) or subscript text (i.e., lower text on a line with a decreased font size), use the sup or sub element, respectively. We also use character entity reference &lt; for a less-than sign and &frac14; for the fraction 1/4 (line 38).

In addition to special characters, this document introduces a horizontal rule, indicated by the <hr /> tag in line 25. Most browsers render a horizontal rule as a horizontal line. The <hr/> tag also inserts a line break above and below the horizontal line.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net