Display an XML Document in a Web Browser

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:

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.)

time.xml in Internet Explorer

Figure 1-1. time.xml in Internet Explorer

time.xml in Mozilla

Figure 1-2. time.xml in Mozilla

time.xml in Opera

Figure 1-3. time.xml in Opera

time.xml in Safari

Figure 1-4. time.xml in Safari

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.

Get XML Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.