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!

[email protected]:~$ curl -l\&geolong=-96.017697

170922Peter Kiewit Institute79037College & Education:UniversityUniversity
1110 South 67th Street
at Pacific StOmahaNE6818241.2436984-96.014670204025543333PKI255
345883Liv Lounge79168Nightlife:LoungeLounge
2279 S 67th St
at Center StOmahaNebraska6810641.2436984-96.01467020255
245578Walmart79221Shops:Department StoreDepartment Store
1606 S 72nd St
at Pine StOmahaNE6812441.2440158-96.024115804023939560541
254875Aksarben Village79196Parks & Outdoors:Plaza / SquarePlaza / Square
6600 Shirley St
at Center StOmahaNE6810641.2414632-96.01205190518
170916Scott Technology Center79115Home / Work / Other:Corporate / OfficeCorporate / Office
6825 Pine Street
2468550Juice Stop79071Food:Juice BarJuice Bar
2119 S 67th St
Shirley StOmahaNE6810641.2403021-96.014660704029343870427
199022Scott Conference Center96353Home / Work / Other:Event SpaceEvent Space
6450 Pine Street
772128Courtyard Aksarben VIllage79273Travel:HotelHotel
1625 S 67th St
at Pine StOmahaNE6810641.243304-96.01434904029514300280
247344Wohlner's Market96359Shops:Food & Drink:GourmetGourmet
2289 S 67th St
at Center StOmahaNE6810641.23806024488222-96.013898849487304025516875672
2564306First Data79115Home / Work / Other:Corporate / OfficeCorporate / Office
6855 Pacific Street
[email protected]:~$

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

[email protected]:~$ curl -l\&geolong=-96.017697 | xmllint --format -
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
101  5265  101  5265    0     0  13778      0 --:--:-- --:--:-- --:--:-- 29914

      Peter Kiewit Institute
        College & Education:University
1110 South 67th Street
at Pacific St Omaha NE 68182 41.2436984 -96.0146702 0 4025543333 PKI 255
... snip ... 2564306 First Data 79115 Home / Work / Other:Corporate / Office Corporate / Office
6855 Pacific Street
Omaha NE 68106 41.2487029 -96.0192553 0 606
[email protected]:~$

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


  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 ( in PHP is really great for small documents. And if you are handling RSS or ATOM then SimplePie ( is an awesome all in one solution.

    Likewise in Python lxml ( and Universal Feed Parser (

Leave A Comment

Your email will not be published.