XML View Plugin
Introduction

XML View Plugin is a Safari plugin that displays XML and JSON data. It always bothered me that Safari doesn’t show raw XML data in a useful way, like Firefox and other browsers do. I had to use “View Source” every time to see the XML data, because Safari seems to interpret the XML elements as HTML, leaving only text element content visible:
Here’s the same data in Firefox:

In projects at work I had to use “View Source” all the time, so I wanted a nicer solution. Joachim Fornallaz and later Juan Germán Castañeda Echevarría, who added JSON support, pitched in, and the result is “XML View Plugin”, a Safari WebKit plugin that registers as a handler for some XML and JSON MIME types and displays the data nicely formatted:

Download & Installation
xmlviewplugin.zipThe plugin requires Mac OS X 10.5 (Leopard). It will not run on older OS versions.
Download and unzip it, then put it into the Library -> Internet Plugins folder in your home folder. Restart Safari and try it out here:
Notes
It registers for the MIME types text/xml and application/xml. If you know of others that it should handle, let me know.
It handles the most common encodings, especially Unicode, but if you encounter an encoding it doesn’t handle, let me know too.
Known Issues
- Versions before 1.2 changed the default font and size for proportional text after an auto-update. If it happened to you, just reset the values in Safari’s Appearance preferences panel. I think the default is Times 16 (but I recommend you play around with these values anyway to find something you like better, while you're at it :-).
- Unfortunately the plugin seems to suppress Safari’s ability to format XML with an associated XSLT style sheet (example here). For now you need to remove the plugin if that is important for you.
- It also seems to break the event detail view of Google Calendar and it doesn’t look like that can be avoided. In the case of the event detail link in their e-mail notifications, they seem to send HTML, but declare it with the wrong MIME type text/xml. (Update: I heard that Google Calendar works in Safari 4 Beta...)
- If you customize the display (see below), you should note that it is currently not possible to use effects that are based on mouse-moved events. This means that you can’t use the CSS
:hoverpseudo-class, and JavaScriptonmouseoveretc. won’t work. This might be a bug in the operating system and I can only wait for it to get fixed. - The ACID 3 test doesn’t run all the way through to 100 in Safari 4. Again, this is a problem of the MIME they use and there’s nothing I can do about it.
- When viewing XML in the formatted and styled view, and the content has a vertical scrollbar, if you click and drag to select the text, while the selection is active, the content scrolls continuously downward.
- Other issues
Customization
You can customize the “Formatted and Styled” view in the plug-in’s Preferences dialog. In this view, the plugin converts the XML document into an HTML page, and you can change the appearance and behavior of that page with CSS and JavaScript in the usual web developer way.
This customization can range from simple syntax coloring color changes to highly interactive mini
applications customized for your particular XML format. The markup uses lots of CSS classes
and you get access to the prototype.js library in the page.
Since you cannot view the source of the internal HTML representation used by the plugin directly in the browser, here’s an example document. If you know XSLT, a look at the transformation the plugin uses to convert XML to HTML might also be useful.
The two default CSS and JavaScript snippets in the Preferences should get you started. If you mess it up, you can always click the Reset button to restore the factory defaults.
Release Notes
License / Source Code
The program is free. If you like it, you can make a donation or send me something from my wish list :-).
The source code Xcode project package is available on github.
The inspiration for this project came from the fantastic ClickToFlash plugin that was in the Mac news recently. Like XML View Plugin, ClickToFlash is implemented as a WebKit plugin. Before reading about it, I did not realize that there’s a convenient, Objective-C based alternative to the old-school Netscape browser plugin API.
