Software > Mac OS X Packages > XML View Plugin Plugin Icon

XML View Plugin

Introduction

XML in Safari without XML View Plugin

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:

XML 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:

XML in Safari with XML View Plugin with syntax coloring and formatting

Download & Installation

xmlviewplugin.zip

The 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:

test.xml

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

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

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.

8. April 2010