If you want something a little more contained, you could install the non-system version of libxml2 via Homebrew.
By default, Brew installs library-only packages outside of the library search path into /usr/local/Cellar, so that you have to specify them explicitly via
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/<version>/include/libxml2
, but you can link (and unlink) any library into the search path at with brew link
, making it the default.