FastXML 0.1.93

May 6th, 2008

A long while ago I started work on a simple hpricot-like interface to libxml for ruby. I've finally push out an initial version, and it's available on the gem servers now just gem install fastxml. You can find the code on github.

Here's a sample of it's usage:

1
2
3
4

require 'fastxml'
doc = FastXml( open( 'test.xml' ) )
(doc/"//a").each { |a| puts a.attr['href'] }

Here's a simple synthetic benchmark. We just load a simple xml file attempt to do an xpath search. It's worth noting that the regular libxml binding is very speedy, because it doesn't actually match anything. Libxml annoyingly want's all xpath queries namespace qualified, that doesn't work out well if you have no root namespace.

(in /Users/segfault/Devel/fastxml)
ruby ./benchmarks/speedtest.rb
                     user     system      total        real
fastxml.new      0.000000   0.000000   0.000000 (  0.001211)
fastxml.to_s     0.000000   0.000000   0.000000 (  0.000537)
fastxml.search   0.000000   0.000000   0.000000 (  0.000315)

hpricot.new      0.020000   0.000000   0.020000 (  0.021583)
hpricot.to_s     0.000000   0.000000   0.000000 (  0.002366)
hpricot.search   0.000000   0.000000   0.000000 (  0.000462)

libxml.new       0.000000   0.000000   0.000000 (  0.001274)
libxml.to_s      0.000000   0.000000   0.000000 (  0.000421)
libxml.search    0.000000   0.000000   0.000000 (  0.000175)

REXML.new        0.020000   0.000000   0.020000 (  0.018574)
REXML.to_s       0.010000   0.000000   0.010000 (  0.003909)
REXML.xpath      0.000000   0.000000   0.000000 (  0.001838)

ruby logo

I've been wearing my ruby slippers to work and I need to share the joy that is rake for .net projects. I've created/modified some rake tasks to ease automation and development of .net projects. Basically I wrap nunit and msbuild in rake and then use the wonder that is rake to create a clean and simple build script. Combine this with cruisecontrol.rb and you have a very nice automated build/testing system in place. Add watir/watin support to taste for that added punch.

You may be wondering why anyone would want to use rake when there are already multiple native build systems (nant and msbuild off the top of my head).

1
2
3
4
5
6
7

<property name="myprj.basedir" value="c:\" />
<property name="filename" value="${path::combine(myprj.basedir,'version.txt')}" />

<if test="${not file::exists(filename) or file::get-length(filename) = 0}">
    <echo message="The version file ${filename} doesn't exist or is empty!" />
</if>

prison picture Why would I want to use xml to write logical expressions? Seriously who wakes up in the morning and looks forward to that? I sure don't. I'd rather use a full fledged programming language, if not for power than for clarity. Anything other than a real language, be it ruby, python or powershell is a pointless waste of time in my opinion. Why spend hours of your life fighting to express yourself within an xml-based cage. Check out this msbuild snippet:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

<ItemGroup>
    <MDForm Include="TestForm1.cs">
        <Author>
            <Name>Ryan Flynn</Name>
            <Email>rflynn@godelwasasmartnut.com</Email>
        </Author>
    </MDForm>
    <MDFormOther Include="..\..\**\MySubProject\*.cs">
        <Author>
            <Name>Mark A. Guzman</Name>
            <Email>mag@godelwasasmartnut.com</Email>
        </Author>
    </MDFormOther>
</ItemGroup>
That looks like a lot of junk to me.

How about this as a reasonable alternative:

1
2
3
4
5

desc "compile cs files"
Rake::CscTask.new do |csc|
  csc.files = FileList[ "**/MySubProject/*.cs" ]
end
Simple, concise and dare I say fun.

Now let's take that last snippet a bit further, as msbuild will do all we want based on the solution (sln) file most of the time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

desc "Run NUnit"
Rake::NUnitTask.new do |nunit|
  nunit.files = FileList['**/*Tests.dll'].exclude(/obj\//)
end

namespace :build do
  desc "Compile Debug"
  Rake::MsbuildTask.new(:debug) do |msbld|
    msbld.solutions = FileList['**/*.sln'].exclude(/obj\//)
    msbld.config = "Debug"
  end

  desc "Compile Release"
  Rake::MsbuildTask.new(:release) do |msbld|
    msbld.solutions = FileList['**/*.sln'].exclude(/obj\//)
    msbld.config = "Release"
  end
end
I think you can guess what's going on here. Now I can do rake build:release and have it run msbuild against the sln file. While that's spiffy, it gets much nicer when you add in automated testing using nunit and watir combined with rspec. Plug this all into cc.rb or even cc.net and you get a very nice simple build system with automated testing. All of that with clean and concise syntax.

I've zipped up the current versions of the rake tasks, you can get them here. Hopefully we can build a nice kit for people wanting to find ruby a niche in their environment.

macports ruby or apple ruby

October 28th, 2007

I've made the jump to Leopard as many other mac users have. With that comes a question, keep using the macports ruby install or use the apple install. At this point I think I'll stick with macports, like Robby Russell I have a good bit of time invested in getting things setup the way I like it. Beyond the existing investment, macports tends to be kept up to date a bit more readily than I think apple can manage. I would like to see the dtrace stuff included in the macports build, hopefully someone will beat me to that one (waaay to many items on my to-do list as is).

mephisto comment regex filter

October 28th, 2007

I finally got annoyed enough at the spammer posting comments on this blog to do something about it. The spammer was consistently posting comments with ^t\d+t$ in some part of the form. Normally I don't actually get bothered by this, as Akismet generally marks those comments as unapproved. In this case, about 1000 got through per day for two days. Each one of those generated an email notifying me of the valid comment. That sucks. So I've created a simple mephisto plugin that prevents the comment from being posted if any field matches a regex. Bugtracking and such are locally hosted in the usual spot. You can install or just get the code from svn://hasno.info/mephisto/plugins//mephisto_comment_regex/ or http://svn.hasno.info/svn/mephisto/plugins/mephisto_comment_regex/. This has only been tested with edge mephisto, ymmv with anything else.

Just in case someone wants to use this and isn't familiar with the rails plugin command line: ./script/plugin install svn://hasno.info/mephisto/plugins//mephisto_comment_regex/

ruby-hl7 0.2.50 released

October 23rd, 2007

This is a maintenance release of the ruby-hl7 library. HL7 is a standard for information exchange in hospitals, it's used for everything from lab work to billing and scheduling. The library can parse or generate HL7 messages. Currently the library only support HL7 2.x, but I'd like to add support for the xml based HL7 3.0 in a future version. You can install the library by typing gem install ruby-hl7. The bugtracker is hosted locally. There is a rubyforge project to store the releases. This release is mainly a bug-fix release, here's the list of changes:
  • Modified the requires due to refactoring in facets 2.x