How to view XML source in Mobile Safari

I see a lot of XML code at Goodreads while working on their iOS app, but some time ago I realized I didn’t have an easy way to see the XML source of a given API response on the iPad. Incidentally, when I realized that I was in bed, and the iPad was the only device within my reach.

So I found this script on which worked fine for HTML pages, but not so much with pure XML content.

Being not a JavaScript expert, it took me a while to make the script work on Mobile Safari, but the following fix seems to do its job. The trick was to replace the usage of document.documentElement.innerHTML with XMLSerializer:: serializeToString(), which serializes a XML tree to a string.

Here’s the whole thing. Just add it as a bookmarklet on your Mobile Safari bookmarks bar:

Source of '+location.href+'');a.close();var b=a.body.appendChild(a.createElement('pre'));'auto';'pre-wrap';b.appendChild(a.createTextNode((new XMLSerializer()).serializeToString(document.documentElement)))})();

The iPad is a computer that you don’t control.

Cory Doctorow nailed it about the iPad:

“The iStore lock-in doesn’t make life better for Apple’s customers or Apple’s developers. As an adult, I want to be able to choose whose stuff I buy and whom I trust to evaluate that stuff. I don’t want my universe of apps constrained to the stuff that the Cupertino Politburo decides to allow for its platform. And as a copyright holder and creator, I don’t want a single, Wal-Mart-like channel that controls access to my audience and dictates what is and is not acceptable material for me to create.”

What kind of spell did Jobs cast on us to make us accept these terms? A computer where we have almost no control on it, yet we want to pay for it?

What is happening to computing?

Around 10 years ago we were horrified by TCPA and Palladium and Trusted Computing and all those future DRM technologies that evoked a really sinister aura of devices whose content we’d be unable to control. But… this is it! It is happening! It has already happened with the iPhone actually. At that time I imagined the killer app that would make this possible was going to be entertainment, and here it is. Everybody loves to be entertained. Now you have a fast and sleek device for it. With a great, “approved” user experience.

The genius here is that Apple understood that to make this happen — to have people accept it — they had to invent a brand new class of devices. Nobody will accept a classic computer with those locked-in limitations. And since the iPad is “revolutionary” and fast, sexy, beautiful, with an engaging UI, people will feel compelled to accept the compromise.

Apple invented a beautiful new device to do whatever the fuck they want, no matter how dirty. But they left the hackers out. Mind you, this is the same company (but is it really?) who made the Apple II+, which shipped with schematics.