The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby, libxml and Windows

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page


Posts: 201
Nickname: cfis
Registered: Mar, 2006

Charlie Savage
Ruby, libxml and Windows Posted: Feb 9, 2007 1:49 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by .
Original Post: Ruby, libxml and Windows
Feed Title: cfis
Feed URL: http://cfis.savagexi.com/articles.rss
Feed Description: Charlie's Blog
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by
Latest Posts From cfis

Advertisement

Let's say my last post tempted you to check out libxml's validation functionality. However, you work in shop that develops on multiple platforms, including Windows, OS X and Linux, so you code has to run on all three platforms.

You happily note that libxml does run on all three platforms, so you download and install it. Next, you fire up your friendly command prompt and ask Ruby Gems to install the appropriate bindings.

Unfortunately, you discover there isn't a pre-built binary for Windows. Being in a hurry, you open up VC++ (experience has taught you that MinGW is a royal pain and will undoubtedly eat up the rest of your day).

Sadly, VC++ doesn't compile the extension. At least with this code, its more pedantic than GCC and flags some sketchy code that increments void pointers. You also note that you have to export the main extension function from the DLL (what developer at Microsoft years ago thought this was a good idea?).

So, to save you the trouble, I've provided a binary that works with Ruby 1.8.5. If you'd like to see the patch, its available at RubyForge.

To use the extesion, copy it into this directory:

ruby\lib\ruby\site_ruby\1.8\i386-msvcrt\xml

Then write code that looks something like this:

require 'xml/libxml_so'

def verify(html)
  dtd = XML::Dtd.new("public", 'xhtml1-transitional.dtd')
  parse =  XML::Parser.string(html)
  parse.validate(dtd)
end

Yup, the "_so" bit is required due to the way the extension is packaged (it shouldn't be, and I was tempted to remove it, but thought it was better to maintain cross-platform compatibility).

Happy hacking!

Read: Ruby, libxml and Windows

Topic: Jim Weirich - Test Driven Development meets Design by Contract Previous Topic   Next Topic Topic: A Sane Way of Sanitizing HTML

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use