From HTML to XHTML
More on XML
XML Document languages are usually bound to a namespace to uniquely identify the element and attribute names with the language. This allows an XML Document to be composed of more than one XML language even if some element and/or attribute names are the same in more than one XML language. The name can have a prefix on it such as <xhtml:a href="...">...</xhtml:a> and <svg:a xlink:href="...">...</svg:a>.
Attributes without prefixes are automatically bound to the same namespace as the element they are on.
Namespaces are declared with xmlns based attributes usually in the Document Element. Namespace values are typically in the form of web address'. But these web address' don't have to actually exist:
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="en-GB">...</xhtml:html>This document contains elements and attributes that are bound to the XHTML namespace with the prefix of xhtml, elements and attributes that are bound to the Scalable Vector Graphics (SVG) namespace with the prefix of svg. SVG also uses attributes from the XLink namespace with a prefix of xlink. The XHTML provides the host structure, the main features of the webpage. SVG describes a 2 dimensional vector image that has a hyperlink feature offered by the XLink language.
There is an original XML namespace which is automatically declared by namespaced-aware XML parsers and have a fixed prefix of xml. Only these attributes are defined by the XML Namespace and can be used in any XML Document:
xml:lang, xml:space, xml:base and xml:idxml:lang is a standard XML version of HTML's lang attribute to state what the spoken language is for the content being used. Such as en, en-GB, en-US, fr, fr-FR, el, el-GR, etc.
xml:space controls if the element content drops the leading and trailing spaces and reduces multiple spaces in between words to single spaces with the value of default and retains the spaces with the value of preserve.
xml:base is the standard XML version of HTML's <base href=""> element. As it is an attribute it can go anywhere in the document on an element.
xml:id is the latest addition to the XML namespace providing a standard XML unique identifier attribute.
You can have one namespace be a default namespace in the XML Document by having no prefix. An example of this is the typical use of XHTML as a host document:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:lang="en-GB">...</html>XML also defines five named entities. Generally XML itself only supports the hex and numbered entities as well as these five named entities:
Less-than character <, greater-than character >, ampersand &, double quote " and introducing the named entity for the apostrophe '.
XML also introduces the Character Data Section:
<![CDATA[ This is like a character escape feature. ]]>It goes in element content and can allow characters such as the five XML named entities to be written as their literal characters and in XHTML it is typically used on script and style elements.
For instance ampersands and less-than and greater-than characters are operators in various scripting languages and usually in XML you would have had to use the named entities as:
<script type="text/javascript" xml:space="preserve">
if (a < b) {
myvar = "correct";
} else {...}
</script>can be written (in native XHTML) as:
<script type="text/javascript" xml:space="preserve"><![CDATA[
if (a < b) {
myvar = "correct";
} else {...}
// ]]>
</script>Even though XML itself only knows these five named entities, XML authors can define others as well as their own using DTDs. XHTML has all the named entities that HTML had defined with the addition of the ' apostrophe named entity.
Another standard feature XML provides is an up-to-date version of <link rel="stylesheet" ... /> elements by using the Processing Instruction with xml-stylesheet as the target:
<?xml-stylesheet type="text/css" href="mystyle.css" title="The main styles"?>These usually go after the XML Prolog and before the DOCTYPE. As you can have rel="alternate stylesheet" in the link element you can have an alternate="yes" attribute in the processing instruction. XML Stylesheet Processing Instructions can only work with native XHTML and other XML languages.
Copyright ©2006-2008 Legend Scrolls and Peter Davison.
All rights reserved.
Skip to content
Home
Contact Me

