Installing XML::DOM on Mac OS X #

When doing XML-ish things in Perl, I tend to favor XML::DOM, not because it has the most natural (and Perl-like) interface (XML::Smart is closer to that goal), but because it follows the W3C DOM syntax. If I'm switching between JavaScript, Perl and a .NET language, not having to look up yet another function naming scheme is convenient.

Having said that, getting XML::DOM to run on Mac OS X isn't quite as intuitive as it could be. 10.3 has a cpan script that invokes the perl CPAN shell (in previous versions it could be reached with perl -MCPAN -e 'shell'). Once the shell is invoked, preferably as root, (and configured, if run for the first time - the and mirrors seem to work pretty well), the module can be installed with the command install XML::DOM. Unfortunately, although the shell is very nice in taking care of all the dependencies, the build/install still fails. The problem lies with XML::Parse, which in turn depends on the Expat XML library. The library has to be pre-installed, but unfortunately the installer isn't smart enough to do this automatically. Expat is available from SourceForge, and installs with the usual incantations on Mac OS X (./configure, make, sudo make install).

Once Expat has been installed, the build process has to be restarted. The CPAN shell keeps a cache of what it previously downloaded, and in this particular case it can be found at ~/.cpan/build/XML-Parser-2.34 (modulo version number changes). Building it by hand isn't all that hard (perl, make, make test, sudo make install), but there is a hitch. One sub-module of XML::Parser is particularly stubborn (one test fails and it refuses to install), so a force install XML::Parser::PerlSAX command from the CPAN shell is required to convince it that all is well. Finally, all the pieces that are needed for XML::DOM are in place, and install XML::DOM can be run again to finish the process.

Post a Comment