Xml For Dummies Chapter 4 Adding Xhtml For The WebPresentation Transcript
XML For Dummies Book Author : Lucinda Dykes & Ed Tittle Slides Prepared By: Son TN Chapter 4 : Adding XTHML for the Web
Contents HTML, XML, and XHTML Comparing XML and HTML XHTML Makes the Move to XML Syntax Convert a document from HTML to XHTML The Role of DOCTYPE Declarations
4.1. HTML, XML, and XHTML HTML, XHTML, and XML represent stages in the development of markup languages. HTML, designed to display content in Web browsers, came first. XML, intended for data exchange, came next. XHTML — which uses the markup tags of HTML and the strict syntax of XML.
4. 1.1 What HTML does best HTML makes our Web world look pretty. Such as a personal site that you create for your family. Most Web sites use straight HTML to display data
4. 1.2 The limits of HTML HTML was enlisted to perform some pretty specify tasks. Allow tight control over document display. Provide the flexibility to describe different, specific types of information and data. Convey information from a variety of media and in a various formats. Define complex linking relationships between document. Publish a single set of information cross a variety of media. Two overarching problems prevent Web designers from achieving this control with HTML: HTML lacks fine controls. Not include mechanisms for the control. … Display vary. Problems with browsers that users view web pages (IE, Firefox…) …
4. 2. Comparing XML and HTML XML and HTML are not the same kind of markup language. But XML and HTML both derive from the same parent SGML. So they must be similar, right ? HTML and XML both use tags and attributes. XML and HTML look similar. HTML defines basic text elements and includes defaults (and more explicit controls) for how text may be displayed in a browser window XML tells us only what each element means. XML says nothing about how elements should or must be displayed — XML separates content and the presentation of that content.
4.2.1 Using XML to describe data XML is not limited to any fixed set of tagsor element types. You can define your own sets of elements and even your own attributes that you may then use within your documents. XML Document HTML Document <html> <p> Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah (XML) blobbity blobbity blobitty blah blah blah blah. blah blah blah </p> <p> Blah blah blah Lucinda Dykes blah Ed Tittel. </p> </html> <Cover> <Abstract> This book is about the foundations of the Extensible Markup Language (XML) and how to use it for your own applications. </Abstract> <AuthorInfo> The authors are <Author>Lucinda Dykes</Author> and <Author>Ed Tittel</Author>. </AuthorInfo> </Cover>
4. 2.2 The benefits of using HTML It’s quick, easy, and cheap. HTML is way easier than the alternative. Anyone can create an HTML document by using a text editor and a little knowledge. Even if you don’t know HTML, you can use an HTML editor — a What You See Is What You Get-style (that is, WYSIWYG-style) editor such as FrontPage or Dreamweaver — to produce readable Web pages in minutes.
4. 2.3 The benefits of using XML XML seems to be brimming with benefits. Unlimited element Structured data Data exchange XML complements HTML XML documents are well formed Self-describing Search engines Updates User-selected view of data Intelligent XML-based pages that contain human-readable data offer exciting potential for users. A Web designer/developer reaps several benefits from XML as well.
The benefits of XML are endless.
4. 3. XHTML Makes the Move to XML Syntax XHTML is the successor to HTML 4.01; in effect, it’s the final version of HTML. XHTML is a clever reformulation of HTML 4 as an application of XML 1.0. Why do we like XHTML? XHTML documents can be viewed, edited, and validated using XML tools. Well-formed XHTML documents mean better-structured documents. XHTML documents can be delivered using different Internet media types and output devices. Using valid XHTML gives you the best chance of having your document displayed the way you intend.
4. 3.1 Making the switch Making the switch from HTML to XHTML means mastering the rules of XHTML — in particular, XML syntax and structure. You have only a few major rules to get under your belt, but you have to follow them if you want to create a valid XHTML document. Every tag in an XHTML document must be closed. Empty elements (elements without content, such as a br tag) must be correctly formatted with a closing slash. All tags must be nested correctly — the tag you open last must be the tag you close first All XHTML tags must be written using only lowercase. All attribute values must be put in quotation marks. An acceptable XML document must be well formed.
4. 3.2 Every element must be closed That all nonempty elements (that is, those that contain actual text) must have a start tag and an end tag. In the case of HTML Doing without an end tag just doesn’t fly in XHTML. You have to add closing paragraph tags where they belong if you want the resulting lines to work right. Is the same as <p>text text text <p>text text text</p>
4. 3.3 Empty elements must be formatted correctly All nonempty XML elements must use both a start tag and an end tag to be correct. An empty element is a singleton tag (also called an empty tag) that hangs around by itself. Empty tags in HTML include the <br>, <hr>, and <img> tags. The hr element looks like this in HTML: In XHTML, it looks like this: <hr> <hr />
4. 3.4 Tags must be properly nested The rules of XHTML syntax say that tags must be nested in the correct order. The rule is always to close first what you opened last, working your way from the inside to the outside tags. Ill formed <p>This book was written by <i><b>Dan Brown</i></b>. Well-formed <p>This book was written by <i><b>Dan Brown</b></i>.</p>
4. 3.5 Case makes a difference HTML is not case sensitive; XHTML is. When you use HTML, it doesn’t matter what case you use for elements and attributes. For example, for the opening body tag, you can use <BODY>, <body>, or even <Body> they all work fine. XHTML, on the other hand, is a bit more finicky about case. All XHTML elements and attribute names must be in lowercase or your page won’t validate. Use any case for the value of an attribute
4. 3.6 Attribute values are in quotation marks In XHTML, all attribute values must be in quotation marks. The following markup works just fine on an HTML page: You have to add quotation marks around the attribute value to create valid XHTML. Table 4-1 highlights the major rules for XHTML syntax and shows how markup looks in HTML and XHTML. <tr align=right> <tr align=”right”>
4. 4. Converting a documentfrom HTML to XHTML
4. 4. Converting a documentfrom HTML to XHTML
4. 5. The Role of DOCTYPE Declarations The DOCTYPE declaration serves several purposes: It allows your page to be validated as XHTML. It tells the browser which version of which markup language you used to create the page and references the specific DTD for that language. It enables your page to be displayed properly in Web-standards-compliant browsers. You have three different DOCTYPES to choose among for an XHTML 1.0 document: strict, transitional, and frames.
4.6 Summary Understanding the limitations of HTML Comparing HTML with XML Getting the best of both worlds: XHTML Converting HTML to XHTML