Use xmllint to Pretty Print API Output

June 10, 2010

I’ve been messing with the Foursquare API and I was getting frustrated by it’s unreadable output. Too much XML, not enough whitespace!

How can we rectify this situation? xmllint! This is part of libxml and should exist on most systems.

So there you go, a handy trick of the day for you.
In case you missed it the short form is:
curl -l [url] | xmllint --format -

Categories: Geek
Tags: , , , ,

Comments

  1. If you don’t mind me asking, why are you using the XML API instead of the JSON API? I’ve all but abandoned XML for just about everything. It’s an absolute pain to work with.

  2. john says:

    I’m not using it in production, but I like it for reading in a shell. Visually I don’t grok JSON as fast as I do XML, but that may just be me.

  3. john says:

    As for working with it, SimpleXML (http://www.php.net/simple_xml) in PHP is really great for small documents. And if you are handling RSS or ATOM then SimplePie (http://simplepie.org/) is an awesome all in one solution.

    Likewise in Python lxml (http://codespeak.net/lxml/) and Universal Feed Parser (http://www.feedparser.org/)

Leave A Comment

Your email will not be published.