XML and IE5, Part 2

by Richard G. Baldwin
baldwin@austin.cc.tx.us
Baldwin's Home Page

Dateline: 1/6/00

Recap from last week:  In my previous article, I introduced you to the use of Microsoft Internet Explorer, version 5, as a viewer for XML files.  I showed you a couple of examples, and promised to provide some of the technical backup in this article.

Separation of content from presentation:  One of the major objectives of XML is the separation of content and presentation.  This is one of the factors that separate XML from HTML.  An HTML viewer (typically a browser) not only knows how to interpret the many possible HTML tags, it also knows how to render the content of the HTML document according to a predefined presentation scheme.

XML documents require separate style sheets:  XML, on the other hand, does not predefine the display characteristics for specific elements.  To be of much use insofar as human consumption is concerned, XML documents require a separate style sheet (or some other mechanism for defining rendering characteristics).

The style sheet (or other mechanism) contains a description of how the XML elements should be displayed.

One document, many purposes:  This separation of XML content from its presentation makes it possible to use the same XML document for a variety of purposes.  For example, the same XML document could be rendered into the newspaper that you find on your driveway each morning and the news page that you find on your computer screen each morning.  Obviously the rendering of the news (and advertisements) would be considerably different for these two purposes, but the content (news) should be the same.

IE5 supports XML with style sheets:  Microsoft® Internet Explorer, version 5 supports style sheets written in either CSS or XSL.

Associating style sheet with XML document:  You can enable the use of a style sheet with an XML document by indicating the type and location of a style sheet with the style sheet processing instruction (style sheet PI).

This is described in the W3C document, Associating Style Sheets with XML documents that you will fine at http://www.w3.org/TR/xml-stylesheet/.

Format of style sheet PI:  The basic form of the style sheet PI looks like this:

<?xml-stylesheet type="text/xsl" href="mystyle.xsl"?>

IE5 uses the PI:  When an XML document is loaded into IE5, the browser searches for the PI.  If it finds a PI, it downloads the style sheet in addition to the XML document and uses the style sheet to display the XML.

Types of style sheets:  You will note that the above syntax for the PI includes a type attribute.  Every style sheet PI must have this attribute, which describes the type of style sheet to apply:

·       "text/css" indicates a CSS style sheet

·       "text/xsl" indicates an XSL style sheet

Location of style sheet:  The href attribute is a URL to the style sheet. Relative URLs are evaluated relative to the URL of the XML document.

According to Microsoft,

“An XML document can include multiple style sheet PIs.  Internet Explorer 5 looks first for a PI of type "text/xsl" and uses the first one it finds. Otherwise it searches for "text/css" PIs and cascades them together using the same process as the HTML LINK element.”

What if there is no PI?  If you load an XML document that doesn’t contain a valid style sheet PI into IE5, it will display the XML document using a default style sheet that is built into IE5.

Default is a tree:  The default style sheet causes the XML document to be displayed as an expanding and collapsing tree.  Here is a screen shot of just such a tree.  The details of the XML document from which this screen shot was generated are provided in my previous article.

Useful for checking XML documents:  This default capability provides a convenient way for XML authors to confirm that their XML document is well-formed. You can also test XSL style sheets and XML Schema documents for being well-formed by opening them in the browser.

To test your XML document, simply double-click it or type its URL into the address bar of the browser. Additional information about well-formed errors is provided to help you find and correct the error.

A well-formed error:  Here is another example from my previous article where I forced a well-formed error by modifying one of the tags in a simple XML document and then loading it into IE5.  As you can see, the browser reported that the book tag was not properly closed.

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct
the error and then click the Refresh button, or try again later.

The following tags were not closed: book

 

According to Microsoft,  

“At times you might want to comment out any style sheet PIs in the source document to isolate source errors from style sheet errors.”

The sequence of events:  IE5 begins displaying the XML document before the document has been completely downloaded. Therefore, when an error occurs towards the end of a long document, IE5 might have already displayed much of the document. When this happens, the error message is inserted directly into the document.  You can view it by scrolling to the bottom of the page.

What about validation?  Apparently, IE5 doesn’t attempt to determine if the XML document is valid.  According to Microsoft,

“When directly browsing XML documents, Internet Explorer 5 loads the specified Document Type Definition (DTD) or XML Schema, but does not report validation errors.”

Have a good Y2K:  To quote a  commercial for a long-distance telephone service that seems to appear every time I turn on the TV, “That’s a wap” for this week.

Fortunately, the world seems to have survived the Y2K bug, my computer is still running, and my Internet connection still works.  So I will continue in my efforts to guide you to the important information about XML.

Coming attractions...

In subsequent lessons, I will discuss the use of style sheets with IE5 to cause the display format to be something other than the default tree format shown above.

The XML octopus

Trying to wrap your brain around XML is sort of like trying to put an octopus in a bottle. Every time you think you have it under control, a new tentacle shows up. XML has many tentacles, reaching out in all directions. But, that's what makes it fun. As your XML host, I will do my best to lead you to the information that you need to keep the XML octopus under control.

Credits

This HTML page was partially produced using the WYSIWYG features of Microsoft Word 2000. The images on this page were used with permission from the Microsoft Word 97 Clipart Gallery.

Copyright 2000, Richard G. Baldwin

About the author

Richard Baldwin is a college professor and private consultant whose primary focus is a combination of Java and XML. In addition to the many platform-independent benefits of Java applications, he believes that a combination of Java and XML will become the primary driving force in the delivery of structured information on the Web.

Richard has participated in numerous consulting projects involving Java, XML, or a combination of the two.  He frequently provides onsite Java and/or XML training at the high-tech companies located in and around Austin, Texas.  He is the author of Baldwin's Java Programming Tutorials, which has gained a worldwide following among experienced and aspiring Java programmers. He has also published articles on Java Programming in Java Pro magazine.

Richard holds an MSEE degree from Southern Methodist University and has many years of experience in the application of computer technology to real-world problems.

baldwin@austin.cc.tx.us
Baldwin's Home Page

-end-
 
 
 

rev0001082204