Indexing script for docbook articles ;)

Today I wanted to have a index.html for a directory full of DocBook articles. Being quite lazy I simply wrote a small Ruby script for doing this since I couldn’t get sed to do what I want:

#!/usr/bin/ruby -w

require 'rexml/document'

def getTitle(file)

        doc =

        title = doc.elements.each("/article/title"){|t| return t.text}

        return File.filename(file)


puts <<EOS

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">



        <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>

        <link rel="stylesheet" type="text/css" href="../_s/style.css"/>






dh =".")

dh.each do |f|

        next if ['.','..'].include?(f)

        path = dh.path+File::SEPARATOR+f

        indexxml = path+File::SEPARATOR+"index.xml"


        if and File.exists?(indexxml)

                puts "<li><a href="#{indexhtml}">#{getTitle(indexxml)}</a></li>"



puts <<EOS





Since I’m currently learning Ruby - or let’s call it refreshing my Ruby knownledge - I’m trying to write most of the scripts I need everyday in Ruby to get some practice. Starting with today I will also post these small scripts here :)

comments powered by Disqus