1 / 57

Computer Science 1000

Computer Science 1000. Markup Languages. Extensible Hypertext Markup Language (XHTML) a stricter version of HTML syntax defined by XML further syntax restrictions element/attribute names must be lowercase attribute values must be quoted widespread browser support. <html>

jenaya
Download Presentation

Computer Science 1000

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Science 1000 Markup Languages

  2. Extensible Hypertext Markup Language (XHTML) • a stricter version of HTML • syntax defined by XML • further syntax restrictions • element/attribute names must be lowercase • attribute values must be quoted • widespread browser support

  3. <html> • defines the root of the document • all other content must be included in html element content • must include xmlns attribute • xml namespacing (xml not discussed here) • attribute value must be "xmlns="http://www.w3.org/1999/xhtml" • must contain exactly two tags • head • body

  4. Attributes • name = "value" pair • included in the start tag of an element • defines some feature of the element • value must be in quotation marks • one element may contain several attributes • ordering of attributes irrelevant • separated by white space <html xmlns="http://www.w3.org/1999/xhtml">

  5. <head> • information typically intended for browser • example tags included in <head>: • Very common: • <title> : the title of the document (appears in tab) • Common: • <script>: contains Javascript code • <meta>: information intended for search engines and servers • Less Common: • <base>: defines URL base for relative links

  6. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is an example! </title> </head> <body> </body> </html>

  7. <body> • the content of your webpage • text, images, tables, forms, etc • <p> • a paragraph of information • logically separates information • eg. in most browsers, two paragraphs separated by blank space

  8. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is an example! </title> </head> <body> <p> This is paragraph one! </p> <p> This is paragraph two! </p> </body> </html>

  9. Whitespace • outside of certain tags (e.g. p), whitespace is basically ignored • hence, you do not need to include your tags on separate lines, as in previous examples • however, you are stronglyrecommended to use whitespace to make your program more readable

  10. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is an example! </title> </head> <body> <p> This is paragraph one! </p><p> This is paragraph two! </p> </body> </html>

  11. <html xmlns="http://www.w3.org/1999/xhtml"><head><title> This is an example! </title></head><body><p> This is paragraph one! </p><p> This is paragraph two!</p></body></html>

  12. Whitespace within tags <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is a space example! </title> </head> <body> <p> This is CPSC 1000: Intro to Computer Science. Your instructor is: Kevin Grant. Your classroom is: UH B756. </p> </body> </html>

  13. HTML & Whitespace • HTML treats whitespace within text tags (e.g. p) as word separators • type of whitespace irrelevant (space, tab, etc) • number of contiguous characters irrelevant, replaced by single blank • In previous example, we could use two <p> elements to separate the text

  14. Whitespace within tags <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is a space example! </title> </head> <body> <p> This is CPSC 1000: Intro to Computer Science. </p> <p> Your instructor is: Kevin Grant. </p> <p> Your classroom is: UH B756. </p> </body> </html>

  15. Unrecognized Elements • what happens if we include an unrecognized element in our document? <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is an example! </title> </head> <body> <p> Hello World! </p> <pp> Good to see you! </pp> </body> </html>

  16. Most browsers attempt to display the page anyway • unrecognized element: ignores markup • unrecognized attribute: ignores attribute <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is an example! </title> </head> <body> <p> Hello World! </p> <pp> Good to see you! </p> </body> </html>

  17. Most browsers attempt to display the page anyway • unrecognized element: ignores markup • unrecognized attribute: ignores attribute <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> This is an example! </title> </head> <body> <p> Hello World! </p> <pp> Good to see you! </p> </body> </html> XHTML considers text directly in <body> element to be a part of an implicit <p> element

  18. Special Characters • Suppose you were making an HTML instructional website:

  19. Will this work? <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> HTML - The P element </title> </head> <body> <p> <p> </p> <p> Used to enclose paragraph information.</p> <p> Example: </p> <p> <p> This is paragraph one. </p> </p> <p> <p> This is paragraph two. </p> </p> </body> </html>

  20. Special Characters • XHTML parser sees < and > as markup • start of a tag • we want < and > to be part of content • solution: use an escape symbol • also called a entity reference • a sequence of symbols that represents a special character • begins with &, ends with ;

  21. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> HTML - The P element </title> </head> <body> <p> &lt;p&gt; </p> <p> Used to enclose paragraph information.</p> <p> Example: </p> <p> &lt;p&gt; This is paragraph one. &lt;p&gt; </p> <p> &lt;p&gt; This is paragraph two. &lt;p&gt; </p> </body> </html>

  22. Fundamental XHTML elements • suppose we were creating a tutorial website for XHTML elements • we are constructing the page for simple lists (to be taken shortly) • Given what we know now, the page might look like this:

  23. Example

  24. Title goes in head element • To achieve a new line, we place in a separate <p> tag • To include special characters in our code, must use references: • < : &lt; • >: &gt;

  25. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple Lists</title> </head> <body> <p>XHTML Elements</p> <p>Topic 6: Simple Lists</p> <p>Purpose:</p> <p>A list is an XHTML construct used to create bulleted or enumerated data.</p> <p>There are two types of simple lists: Unordered and ordered. A more complex type of list, definition, can be found at /xhtml/def.html.</p> <p>In an unordered list, each element is displayed as a bullet. This is for data whose ordering is unimportant. Unordered lists use the tag &lt;ul&gt;. Each item in the list is denoted by &lt;li&gt;. </p> <p>Example:</p> <p>&lt;ul&gt;</p> <p>&lt;li&gt; Ham &lt;/li&gt;</p> <p>&lt;li&gt; Pineapple &lt;/li&gt;</p> <p>&lt;li&gt; Cheese &lt;/li&gt;</p> <p>&lt;/ul&gt;</p> </body> </html>

  26. Result • page is: • boring • ugly • code is difficult to read

  27. Problem 1: No emphasis on any data These have same visual weight

  28. Headings • produce section headings • allow information to categorized hierarchically • 6 levels provided by HTML • <h1> - highest level • <h2> - second highest level • … • <h6> - 6th highest level • Browsers have a default on how these headings are displayed

  29. Example Top-level Second-level Third-level

  30. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple Lists</title> </head> <body> <h1>XHTML Elements</h1> <h2>Topic 6: Simple Lists</h2> <h3>Purpose:</h3> <p>A list is an XHTML construct used to create bulleted or enumerated data.</p> <p>There are two types of simple lists: Unordered and ordered. A more complex type of list, definition, can be found at /xhtml/def.html.</p> <p>In an unordered list, each element is displayed as a bullet. This is for data whose ordering is unimportant. Unordered lists use the tag &lt;ul&gt;. Each item in the list is denoted by &lt;li&gt;. </p> <h3>Example:</h3> <p>&lt;ul&gt;</p> <p>&lt;li&gt; Ham &lt;/li&gt;</p> <p>&lt;li&gt; Pineapple &lt;/li&gt;</p> <p>&lt;li&gt; Cheese &lt;/li&gt;</p> <p>&lt;/ul&gt;</p> </body> </html>

  31. Problem 2: Spacing These are all defined in separate paragraphs, even though the data belongs together. Hence, a space is included between elements.

  32. The <br> tag • provides a line break in the code • breaks occur in the same paragraph of information • allows visual separation of information, while maintaining logical coupling of information (within the <p> tag) • uses the <br> tag

  33. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple Lists</title> </head> <body> <h1>XHTML Elements</h1> <h2>Topic 6: Simple Lists</h2> <h3>Purpose:</h3> <p>A list is an XHTML construct used to create bulleted or enumerated data.</p> <p>There are two types of simple lists: Unordered and ordered. A more complex type of list, definition, can be found at /xhtml/def.html.</p> <p>In an unordered list, each element is displayed as a bullet. This is for data whose ordering is unimportant. Unordered lists use the tag &lt;ul&gt;. Each item in the list is denoted by &lt;li&gt;. </p> <h3>Example:</h3> <p> &lt;ul&gt;<br></br> &lt;li&gt; Ham &lt;/li&gt;<br></br> &lt;li&gt; Pineapple &lt;/li&gt;<br></br> &lt;li&gt; Cheese &lt;/li&gt;<br></br> &lt;/ul&gt; </p> </body> </html>

  34. <br></br> • Note that these tags contain no content • emptytag • Shorthand for empty tags: • <element-name /> <p> &lt;ul&gt;<br /> &lt;li&gt; Ham &lt;/li&gt;<br /> &lt;li&gt; Pineapple &lt;/li&gt;<br /> &lt;li&gt; Cheese &lt;/li&gt;<br /> &lt;/ul&gt; </p>

  35. This isn't bad, but we can do better • Notice that our tags have no indenting • Placing a <br /> after each line is cumbersome • Difficult to differentiate the example code from the other content

  36. The <pre> tag • preformatted text • overrides whitespace processing and font rendering • all whitespace is preserved • tags still work in preformatted text • entity references still work in preformatted text

  37. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple Lists</title> </head> <body> <h1>XHTML Elements</h1> <h2>Topic 6: Simple Lists</h2> <h3>Purpose:</h3> <p>A list is an XHTML construct used to create bulleted or enumerated data.</p> <p>There are two types of simple lists: Unordered and ordered. A more complex type of list, definition, can be found at /xhtml/def.html.</p> <p>In an unordered list, each element is displayed as a bullet. This is for data whose ordering is unimportant. Unordered lists use the tag &lt;ul&gt;. Each item in the list is denoted by &lt;li&gt;. </p> <h3>Example:</h3> <pre> &lt;ul&gt; &lt;li&gt; Ham &lt;/li&gt; &lt;li&gt; Pineapple &lt;/li&gt; &lt;li&gt; Cheese &lt;/li&gt; &lt;/ul&gt; </pre> </body> </html>

  38. Text Decoration • it would be nice to emphasize certain parts of the text with • bold • italics • monospace font, to show our example XHTML code (like in the pre tag)

  39. Bold Italic Monospaced

  40. Font Style Elements in XHTML

  41. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple Lists</title> </head> <body> <h1>XHTML Elements</h1> <h2>Topic 6: Simple Lists</h2> <h3>Purpose:</h3> <p>A <b>list</b> is an XHTML construct used to create bulleted or enumerated data.</p> <p>There are two types of simple lists: <i>unordered</i> and <i>ordered</i>. A more complex type of list, <i>definition</i>, can be found at /xhtml/def.html.</p> <p>In an <b>unordered list</b>, each element is displayed as a bullet. This is for data whose ordering is unimportant. Unordered lists use the tag <tt>&lt;ul&gt;</tt>. Each item in the list is denoted by <tt>&lt;li&gt;</tt>. </p> <h3>Example:</h3> <pre> &lt;ul&gt; &lt;li&gt; Ham &lt;/li&gt; &lt;li&gt; Pineapple &lt;/li&gt; &lt;li&gt; Cheese &lt;/li&gt; &lt;/ul&gt; </pre> </body> </html>

  42. <strong> and <em> • while <b> and <i> are part of XHTML, they are not recommended • strictly visual markup, rather than semantic • instead, use <strong> for bold, and <em> for italic • received better by other technologies • screen readers

  43. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Simple Lists</title> </head> <body> <h1>XHTML Elements</h1> <h2>Topic 6: Simple Lists</h2> <h3>Purpose:</h3> <p>A <strong>list</strong> is an XHTML construct used to create bulleted or enumerated data.</p> <p>There are two types of simple lists: <em>unordered</em> and <i>ordered</i>. A more complex type of list, <em>definition</em>, can be found at /xhtml/def.html.</p> <p>In an <strong>unordered list</strong>, each element is displayed as a bullet. This is for data whose ordering is unimportant. Unordered lists use the tag <tt>&lt;ul&gt;</tt>. Each item in the list is denoted by <tt>&lt;li&gt;</tt>. </p> <h3>Example:</h3> <pre> &lt;ul&gt; &lt;li&gt; Ham &lt;/li&gt; &lt;li&gt; Pineapple &lt;/li&gt; &lt;li&gt; Cheese &lt;/li&gt; &lt;/ul&gt; </pre> </body> </html>

  44. Horizontal Rules • suppose we add a second set of information to the page • a discussion about ordered lists, in addition to unordered lists • we will use similar formatting (headings, strong, em) to achieve similar effects for this discussion

More Related