Inline styles make XML files easy to share in IE5

John Turnbull shows us how to add CSS styles to an XML document so that Internet Explorer 5 will display it.

Inline styles make XML files easy to share in IE5
John Turnbull

You may know that you can view XML in Internet Explorer 5. And that you can use CSS to style your XML document just by adding a reference to an external CSS stylesheet. This is great, but means that if you want to send an XML file around the office for people to look at, you need to send two files (the XML file and a CSS stylesheet). That's a serious inconvenience for people who are used to simply double-clicking on attachments to view them.

There is an easy solution. You can actually add CSS styles to an XML document and IE5 will display it, styles and all. This means you can send a single file, and if the recipient has IE5, the file can be double-clicked for display. Your reader never even needs to know that the file is really an XML document.

This is how you do it:

Add the stylesheet processing instruction just after the XML declaration at the beginning of the document, like so:

<?xml version "1.0"?>
<?xml-stylesheet type="text/css"?>

Next, change the start tag of your root element to include a reference to the HTML namespace. For example, it your root element is named "story" then change the start tag from this

<story>

to this

<story xmlns:HTML="http://www.w3.org/Profiles/XHTML-transitional">

If you need more information on namespaces, see http://www.softquad.com/resources/xml/tips/namespaces.html

Finally, you just add the STYLE block. It can contain as many or as few CSS styles as you like. This one has a style for an element called "title".

<HTML:STYLE>
title { 
  font-family: Georgia, "Times New Roman", serif;
  font-weight: bold;
  color: #FF0000;
  margin-bottom: 1px;
  text-transform: uppercase;
  background-color: #FFFFFF;
}
</HTML:STYLE> 

Add CSS styles for as many of your elements as you want.

That's it! Open your file by double-clicking it. If IE5 is the application that normally opens XML files on your computer -- and it usually is -- you'll get a document that looks the way you intended but is easy to open. Now you can send a single XML file that anyone can view in style.

--------------------------------------------------------------------------------

John Turnbull began working with SGML technologies in 1994 in consumer publishing, engineering documentation, financial systems and classified advertising. He joined SoftQuad in 1996 where he followed the creation of the XML 1.0 specification and worked in both technical writing and document conversion. He is currently the XMetaL Product Manager.).

Did you like this tip? Send us an email to let us know. We want to know what you think.

Related Book

Core CSS: Cascading Style Sheets, 1/e
Author : Keith Schengili-Roberts
Publisher : Prentice Hall
Published : May 2000
Summary :
In this example-rich book, Keith Schengili-Roberts shows experienced Web developers all they need to know to achieve great results with the latest style-sheet technologies. Schengili-Roberts provides in-depth coverage of both CSS1 and the recent CSS2 standard, taking care to explain the differences between the two. Understand key CSS2 families of properties, including aural (sound-based) style sheets, automatically generated content, user interface properties and much more.


This was first published in June 2001

Dig deeper on XML and XML schema

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close