Displaying XML in the Chrome browser

65

14

I love the Chrome browser, but I use XML quite a lot in my development work and when I view it in Chrome I just get the rendered text.

I know that the source view is slightly better, but I'd really like to see the layout and functionality that Internet Explorer adds to XML, namely:

  • Highlighting
  • Open/close nodes

Any ideas how I can get this on Chrome?


UPDATE:

The XMLTree Extension is available on Google Chrome Extension Beta Site.

Josh

Posted 2009-07-15T11:24:44.653

Reputation: 1 572

Enabled in Google Chrome 11 dev by default – NARKOZ – 2011-03-16T14:06:47.277

Nowadays, accepting answers and bounties are no longer linked. So, feel free to accept your own answer instead! – Arjan – 2013-08-15T12:23:50.443

1Hmm... uh, firefox? – RCIX – 2009-07-21T05:50:34.657

32come on guys - use firefox answers aren't really helpful. – Josh – 2009-07-21T09:34:32.307

3Nice extension. Why don't you move your solution into its own answer, so you can accept it and it can be upvoted? – arathorn – 2009-07-22T15:28:07.680

@arathorn - i have now added the plug-in as an answer - thanks. – Josh – 2009-07-22T15:53:32.933

@Josh: Don't you want to change your accepted answer, also? (I assume that's possible.) – arathorn – 2009-07-22T16:23:18.723

@arathorn - no it's not possible as it was a featured question - thanks anyway :) – Josh – 2009-07-22T16:43:19.350

Answers

18

I guess your best bet is to use a bookmarklet or install Greasemetal (which is Firefox' Greasemonkey for Chrome), combined with a script like XML Tree (old, but the source may still help). A more generic syntax highlighting script may help as well, but I doubt if you'll easily find one with code folding.

Note that whitespace might matter in XML. Not all XML viewers respect that; the screenshot created by the abovementioned XML Tree for the example XML does not respect it for the line Sample XML element containing a lot of text, enough to be put on a separate line.

(Unfortunately jsgui.com/xml-viewer is not responding while I am writing this.)

EDIT: How to print pretty xml in javascript? on Stack Overflow mentioned a newer version of XML Tree: Pretty XML Tree, using XSLT and claims to be faster. The demo does not respond to clicking in my Safari or Firefox, but may be helpful anyway.

Arjan

Posted 2009-07-15T11:24:44.653

Reputation: 29 084

i've updated my extension to use xslt and a simular idea to pretty xml tree - but i hope working better :) - let me know what you think - same link as before. – Josh – 2009-08-05T08:24:21.027

(I'm still not using Chrome, but given the earlier comments I read at http://www.chromeplugins.org/google/chrome-plugins/new-ext-xml-tree-user-friendly-xml-view-7963.html I'm sure people are happy!)

– Arjan – 2009-08-05T19:44:00.400

thanks - put me on the right track. got a working extension based on the xml tree script. – Josh – 2009-07-22T10:19:08.760

@Josh, though I'm not using Chrome: thanks for the plug-in! – Arjan – 2009-07-22T14:27:52.730

28

I have now created a simple extension to add this functionality.

UPDATE see here for the extension.

Josh

Posted 2009-07-15T11:24:44.653

Reputation: 1 572

Can you make it work for download links to XML files? Chrome keeps asking me to save the file to disk :( – sorin – 2013-08-09T11:00:11.133

1Josh, that extension is now maintained by someone else? – Arjan – 2013-08-15T12:07:06.300

6

As far as I understand it the limitation is actually in the webkit rendering engine rather than in Chrome itself. I doubt we'll decent XML rendering in Chrome before they properly launch extensions, at which time someone will be able to code a community extension to handle text/xml files.

If you want an alternative to IE, the Firefox rendering of XML is pretty good.

Russell Heilling

Posted 2009-07-15T11:24:44.653

Reputation: 690

Either that, or they'll just create an extension equivalent to Firefox's "IE Tab," or perhaps "Firefox Tab" if you will. https://addons.mozilla.org/en-US/firefox/addon/1419

– MatrixFrog – 2009-07-19T20:36:04.407

1@MatrixFrog FF-tab for chrome, in which you can run IE-Tab for FF? ;D – pavsaund – 2009-07-22T06:57:52.050

6

If you right-click on a node, and click "Inspect Element", you should get the WebKit Web Inspector, which has lots of fancy features including what you need; this should work for XML in addition to just HTML. Here's a screenshot from Safari, which has the same inspector:

Web Inspector

jtbandes

Posted 2009-07-15T11:24:44.653

Reputation: 8 350

2+1 this looks like the original poster's answer. I just checked and the "inspect element" option is there when viewing a raw XML file. It would be nice if this was the default rendering option for non HTML XML files; however two clicks isn't that much of a price to pay :) – Russell Heilling – 2009-07-22T08:16:27.807

very cool - just a shame its not the default option for xml. – Josh – 2009-07-22T08:30:23.983

Well, yeah. The problem is the browser has no way to know whether you want it to render the document or not, since XML is a perfectly valid medium for web pages (for example, http://homepage.mac.com/nathan_day/pages/news.xml). The Web Inspector is really just a developer tool (an awesome one!).

By the way, Josh, did this count as the answer to the original question?

– jtbandes – 2009-07-22T08:43:56.307

It is a shame it's not the default renderer. Several times I have been forced to use IE for this purpose even though chrome is my browser of choice.

Regarding, how will the browser know how to display the document? I don't care! Somehow IE and Firefox figure it out. Maybe something in the stylesheet, guesswork, magic...just do it! – Tundey – 2009-07-22T14:30:06.517

@jtbandes - the script idea from @Arjan van Bentem was the best answer as it helped create the extension which i've also added as an answer. – Josh – 2009-07-22T15:55:49.980

Hm, alright, though the Web Inspector is built in and doesn't require an extension. And it does more. – jtbandes – 2009-07-22T23:22:45.083

4

Chrome dev channel now features an XML viewer, which is invoked if the XML does not have an associated XSL (the same holds for the WebKit nightlies). Happy viewing!

apavlov

Posted 2009-07-15T11:24:44.653

Reputation: 41

1

Yup! It's landed in the stable releases now I believe. http://code.google.com/p/chromium/issues/detail?id=434

– ken – 2011-05-10T18:00:40.340

2

I've tried many, but only XV — XML Viewer works for both regular XML and RSS feeds (if you turn it on in the settings).

John Sheehan

Posted 2009-07-15T11:24:44.653

Reputation: 1 636

That's great, that option was exactly what I was looking for. – huyz – 2014-08-13T10:00:10.930

1

No need for fancy extensions(Which breaks if you load a 1MB sized XML file).

This post is old, but right now Chrome has fixed the bug and has added support for viewing XML directly in the browser. Just drag and drop any XML file and you can see the collapsible tree view of the file. It also supports viewing RSS feeds.

Lucky

Posted 2009-07-15T11:24:44.653

Reputation: 422

0

In my case (SharePoint 2013 REST API response ) XML Tree wins XV — XML Viewer

  • perfect Tag matching and highlighting on mouse over
  • unbeatable intuitive tree view format

Extra advanced features

  • XPATH query

    enter image description here

(in fact i installed XV first and it did nothing with my xml, but XML tree rocks it)

Iman Abidi

Posted 2009-07-15T11:24:44.653

Reputation: 483