Saturday, March 20, 2010

Building XMLStarlet in Snow Leopard (OSX 10.6)

XMLStarlet is a command line XML toolkit. Very useful if you want to parse some data from a webpage, RSS feed of similar. XMLStarlet does not provide a binary version for Snow Leopard. They do however provide their source under the MIT licence. So your free to download, build and modify.

To get XMLStarlet up and running on Snow Leopard is nice and easy.

  1. Install Xcode with the Unix the Unix Dev Support Option (see my past post about building wget for more details on this).

  2. Go download yourself a copy of the XMLStarlet source (I am using v 1.0.1).

  3. XMLStarlet requires libxml2 and libxslt. Snow Leopard ships with both these libraries installed, however they are not in the location expected by the XMLStarlet build script so some symlinks are required. Enter the following in a terminal:
    sudo ln -s /usr/lib/libxslt.1.dylib /usr/lib/libxslt.a
    sudo ln -s /usr/lib/libexslt.dylib /usr/lib/libexslt.a
    sudo ln -s /usr/lib/libxml2.dylib /usr/lib/libxml2.a
    
    
  4. Unpack the XMLStarlet tarball by double clicking it in Finder.
    Take note of the name of the newly unpacked directory (something like xmlstarlet-1.0.1).

  5. Open a terminal and cd to where you just unpacked (by default this will be the directory below).
    cd ~/Downloads/xmlstarlet-1*
    
    
  6. Run the configure script:
    ./configure
    
    
  7. Run the builds
    make
    
    
  8. Run the installer:
    sudo make install
    
    
  9. Finally, to test that the install worked correctly enter the following in a terminal:
    TA:~ troy$ xml 
    XMLStarlet Toolkit: Command line utilities for XML
    ... 
    XMLStarlet is a command line toolkit to query/edit/check/transform XML documents 
    (for more information see http://xmlstar.sourceforge.net/)
    
    
Enjoy.