News

Monday, July 23, 2007

XML Basics - An Introduction to XML

Introduction to XML by Jan Egil Refsnes
What is XML, and how does it differ from HTML.
 
How XML can be used by Jan Egil Refsnes
Some of the different ways XML can be used.
 
XML Syntax by Jan Egil Refsnes
The syntax rules of XML. How to write well formed XML documents.
 
XML Attributes by Jan Egil Refsnes
How to use attributes to provide additional information about elements.
 
XML Validation - Document Type Definition by Jan Egil Refsnes
Using a DTD is the formal way to describe a valid XML document.
 
XML support in Internet Explorer and Netscape Navigator by Jan Egil Refsnes
About the support for XML in the two most famous browsers.
 
Viewing XML by Jan Egil Refsnes
How to view XML files in your browser.
 
Displaying XML by Jan Egil Refsnes
How to display XML content using JavaScript, CSS or XSL
 
XML Examples by Jan Egil Refsnes
A collection of examples from all the chapters of this Web.
 
XML Links by Jan Egil Refsnes
A collection of useful XML links.
 

Thursday, July 12, 2007

How to add style to XML

The CSS2 Recommendation contains a brief tutorial on using CSS with XML (see § 2.2). At the time CSS2 was written the official specification for style in XML wasn't ready. Here is what that tutorial should have contained. Note that the examples use CSS, but in most cases the style rules can also be written in XSL.
 
External style sheets
 
HTML has a link element to link to external style sheets, but not every XML-based format will have such an element. If there is no suitable element, you can still attach external style sheets by means of the xml-stylesheet processing instruction like this:
 
<?xml-stylesheet href="my-style.css" type="text/css"?>
... rest of document here...
 
This processing instruction (PI) must come before the first tag of the document. The type="text/css" is not required, but it helps the browser: if it doesn't support CSS, it knows it won't have to download this file.
 
Just as with the link element of HTML, there can be multiple xml-stylesheet PIs and they can have attributes to set the type, medium and title.
 
Here is a larger example. Let's assume we have three style sheets, one that sets the basic display type of each element (inline, block, list-item, etc.) and two different ones that each set colors and margins. The two last ones are each other's alternative, and the reader of the document may choose which one to use. Except when the document is printed, in which case we only want to use the last style. Here is the common style sheet:
 
/* common.css */
INSTRUMENT { display: inline }
ARTICLE, HEADLINE, AUTHOR, PARA { display: block }
 
This is one of the alternative styles, in a file called "modern.css":
 
/* modern.css */
ARTICLE { font-family: sans-serif; background: white; color: black }
AUTHOR { margin: 1em; color: red }
HEADLINE { text-align: right; margin-bottom: 2em }
PARA { line-height: 1.5; margin-left: 15% }
INSTRUMENT { color: blue }
 
And here is the other one, called "classic.css":
 
/* classic.css */
ARTICLE { font-family: serif; background: white; color: #003 }
AUTHOR { font-size: large; margin: 1em 0 }
HEADLINE { font-size: x-large; margin-bottom: 1em }
PARA { text-indent: 1em; text-align: justify }
INSTRUMENT { font-style: italic }
 
The XML document with these three style sheets linked to it looks like this:
 
<?xml-stylesheet href="common.css" type="text/css"?>
<?xml-stylesheet href="modern.css" title="Modern" media="screen"
  type="text/css"?>
<?xml-stylesheet href="classic.css" alternate="yes"
  title="Classic" media="screen, print" type="text/css"?>
<ARTICLE>
  <HEADLINE>Fredrick the Great meets Bach</HEADLINE>
  <AUTHOR>Johann Nikolaus Forkel</AUTHOR>
  <PARA>
    One evening, just as he was getting his
    <INSTRUMENT>flute</INSTRUMENT> ready and his
    musicians were assembled, an officer brought him a list of
    the strangers who had arrived.
  </PARA>
</ARTICLE>
 
For more details, see the W3C Recommendation "Associating Style Sheets with XML documents"
 

Tuesday, July 3, 2007

Building Accessible Web Sites with XHTML and CSS Problem Design Solution

  • Shows Web developers how to make the transition from HTML to XHTML, an XML-based reformulation of HTML that offers greater design flexibility
  • Demonstrates how to work with CSS (Cascading Style Sheets)–now supported by ninety percent of browsers and integral to new site-building tools from Macromedia and others–and implement a consistent style throughout and entire site
  • Explains how to make a site accessible to people with impaired vision, limited hand use, dyslexia, and other issues–now a legal requirement for many sites in the U.S. and the U.K.
  •