CHAPTER 3 WEB VOCABULARIES XHTML Tools You can use three kinds of tools to edit your XHTML documents: Simple text editors XML editors XHTML editors Each of these tool types offers different benefits. Let s explore these types in more detail. Text Editors Because XHTML is a text-based format, you can create document markup in text editors, including Notepad on Windows, SimpleText on Macintosh, and Vim on Linux. These editors aren t specifically designed to create XHTML or XML documents, so they have very few features that can assist with authoring. They can t provide information about whether a document is well formed or valid, and they don t provide any type of color-coding for the text. Although they have significant limitations, text editors are often useful because they exist on almost all computers and start up very quickly. The most useful text editors can display line numbers, which are invaluable for tracking down parser errors. XML Editors Many XML editors are designed to work specifically with XML documents. These editors offer many advantages over text editors, not the least of which is automatic color coding for elements within the document. Although not written specifically for XHTML, XML editors can still provide tag completion so your elements close automatically. In addition, XML editors allow you to check that your document is well formed and valid, based on its DTD or XML schema. Some popular XML editors include Altova s XMLSpy: http://www.altova.com/products_ide.html Stylus Studio s XML Editor: http://www.stylusstudio.com/xml/editor/ Topologi s Markup Editor: http://www.topologi.com/products/tme/index.html TIBCO s Turbo XML: http://www.tibco.com/software/business_integration/ turboxml.jsp SyncRO Soft s : http://www.oxygenxml.com/index.html/ Blast Radius XMetal: http://www.xmetal.com/en_us/products/xmetal_author/index.x Wattle Software s XMLwriter: http://www.xmlwriter.net/ Most of these products offer a trial version so that you can test whether they ll suit your needs. Visit our web design programs services for an affordable and reliable webhost to suit all your needs.
CHAPTER 3 WEB VOCABULARIES CHOOSING AN ENCODING UTF-8 is a Unicode character set that supports the first 128 ASCII characters, as well as additional charac- ters. Documents using only simple ASCII characters can use UTF-8 encoding. The basic ASCII character set doesn t include European characters that include accents, and the numeric values for each character may vary depending on the specified encoding. If you re running an English version of Windows, your default encoding is compatible with ISO-8859-1. This encoding is supported widely, so changing the encoding declaration to ISO-8859-1 allows European characters to display correctly. Encoding rules are often complex. XML supports UTF-8 and UTF-16 encoding by default. UTF-16 is a large character set that includes many Chinese and Japanese characters, among others. In order to have numeric values for all of the characters, it uses two or more bytes for each character, instead of one byte as in UTF-8 and ASCII. Simple text editors may not support encoding other than UTF-8 or ASCII. For more infor- mation about different encoding specifications, visit http://www.unicode.org/. Again, this line tells the browser what type of content the document contains. In the preceding tag, you specify text/html as the document type and ISO-8859-1 as the encoding. If a document contains both the XML declaration and the element, the browser uses the encoding value in the XML declaration. Browsers that don t support the XML declaration use the value. You can also use the HTTP header Content-Typeto specify encoding on the web server. This approach provides the most reliable way to specify the encoding in an XHTML document. You can set the header using any server-side technology. Specifying Language HTML 4.0 and XHTML 1.0 allow you to specify the language for a document or element using the lang attribute. Web browsers can use this information to display elements in language- specific ways. For example, hyphenation may change depending on the language in use. Additionally, screen readers may read the text using different voices, depending on the language specified. The following langattribute specifies the U.S. version of English as the language for the document:
You can find out more about which attribute values to use at http://www.w3.org/TR/ REC-html40/struct/dirlang.html. XHTML 1.1 replaces the lang attribute with xml:lang. In addition to XHTML, many other web vocabularies use this attribute from the xml namespace. This makes XHTML much more compatible with other XML applications. If you want a quick refresher on namespaces, see the section, Understanding the Role of XML Namespaces, in Chapter 2. In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
CHAPTER 3 WEB VOCABULARIES In XHTML 1.1, however, the W3C permits only the idattribute: Again, older browsers expect you to use the name attribute. Because of this, some XHTML 1.1 pages don t work in early browser versions. Nesting Tags The HTML language didn t specify how you should nest tags, so writing something like the following didn t cause an error:
This doesn t work in XHTML; you need to rewrite the code so the tags close in the correct order:
Character Encoding Specifying the document encoding is very important, and in some cases required, so that the document displays correctly within different web browsers. Document encoding defines a numeric value for each character. Different encoding schemes sometimes use these values in different ways. Most browsers and computers support ASCII encoding, which assigns values to the 128 most commonly used characters. These characters are compatible across different platforms. If you re using characters with values higher than 128, you must specify the character set so that the browser knows which character to display for a given value. Within XHTML, you can specify the character set that your document is using in several ways, including Using the XML declaration Using the element Using external means You can use any of these methods alone or in combination. Using all methods together ensures that the browser understands the document s encoding, even if it doesn t support that encoding. Again, including encoding declarations may confuse some older browsers. Let s look at each of the methods more closely. Specifying encoding using the XML declaration is very easy, and you ve seen it in the examples in Chapter 1: You can specify encoding in a tag by adding the following element to the
section of your XHTML document: If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.
CHAPTER 3 WEB VOCABULARIES In HTML, empty elements appeared like this: In XHTML, empty elements can either appear with an immediate opening and closing tag, such as or in the short form, such as In the short form, you add a forward slash (/) before the closing angle bracket (>). This tells the XML or XHTML parser that the element is empty. Although both forms are legal XHTML, very old browsers have problems reading opening and closing tags for elements that are empty. It s much better to use the short form for empty elements. These browsers also may have difficulty with the forward slash character, so, if you re targeting them, it s also good practice to add a space before the character ( ). Attributes In addition to using the proper case for attribute names, you also need to make sure that you write them correctly. In HTML, you could write attribute values without quotation marks. For example, the following was legal in HTML:
HTML also allowed you to minimize attributes: Neither of these options is acceptable in XHTML. All attributes must have a value, even if it s blank, and you must enclose all values in matching quotation marks:
In the preceding
element, you add quotation marks around the attribute value 4. In the