Hack 2 Display an XML Document in a Web Browser

   

figs/beginner.gif figs/hack2.gif

The most popular web browsers can display and process XML natively. Nowadays, it's just a matter of opening a file.

XML is now mature enough that recent versions of the more popular web browsers support it natively. At the time of writing, the most recent versions of these browsers include:

  • Microsoft Internet Explorer 6 (http://www.microsoft.com/windows/ie/)

  • Mozilla 1.7 and Mozilla Firefox 0.9 (http://www.mozilla.org)

  • Netscape 7.1 (http://channels.netscape.com/ns/browsers/download.jsp)

  • Opera 7.51 (http://www.opera.com)

  • Apple's Safari 1.2 (http://www.apple.com/safari/)

This means that you can display raw, unstyled XML documents (files) directly in web browsers, with varying results.

The browsers use their own internal mechanisms to display XML. Internet Explorer (IE), for example, uses the default stylesheet defaultss.xsl, which is stored in a MSXML dynamic link library (DLL) msxml.dll, msxml2.dll, or msxml3.dll. You can examine this stylesheet in IE by entering res://msxml3.dll/DEFAULTSS.xsl in the address bar. (This works for msxml.dll, msxml2.dll, or msxml3.dll, but not msxsml4.dll, the latest version.) If you have Visual Studio (http://msdn.microsoft.com/vstudio/), you can use the Resource Editor to edit and save this stylesheet back in the DLL (http://netcrucible.com/xslt/msxml-faq.htm#Q19).

To open an XML document such as time.xml (similar to start.xml), go to File Open File or File Open, depending on the browser, and select the document.

Figures Figure 1-1, Figure 1-2, Figure 1-3, and Figure 1-4 show time.xml displayed in IE, Mozilla, Opera, and Safari, respectively. (Mozilla, Firefox, and Netscape have very similar output, so only Mozilla is shown in Figure 1-2. All three of these browsers do not show the XML declaration of time.xml.)

Figure 1-1. time.xml in Internet Explorer
figs/xmlh_0101.gif


Figure 1-2. time.xml in Mozilla
figs/xmlh_0102.gif


Figure 1-3. time.xml in Opera
figs/xmlh_0103.gif


Figure 1-4. time.xml in Safari
figs/xmlh_0104.gif


IE and Mozilla show a tree representation of time.xml, but Opera and Safari only show the text content of the elements in the document.



XML Hacks
XML Hacks: 100 Industrial-Strength Tips and Tools
ISBN: 0596007116
EAN: 2147483647
Year: 2006
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net