I stayed up far too late last night playing with Erlang and friends – much longer than planned due to a few hitches. I did manage to complete more or less what I’d planned in the end though, so here is the documentation.
The initial environment is that built up over my previous posts with one slight change – I had to switch to revision 171 of ErlyWeb from SVN, as the Mnesia driver is temporarily broken in more recent revisions.
Step one was to create the Mnesia database and import some data I already had in XML format. After a bit of head-scratching and cursing, I came up with djimport.erl. It’s not all pleasant (see the last function, which was the source of most of the cursing until I gave in and committed that horrific crime), but it did suck in 6714 ‘record’ records quickly and without even complaining about the awful choice of record name. I used the following Erlang command-line to run it:
erl -s djimport -sname dj -mnesia dir '"db"'
Step two was to extend the ErlyWeb app created in the previous post by adding a new component, as follows:
erl -pa /home/ciaran/erlyweb/ebin
1> erlyweb:create_component("record", "/home/ciaran/dj").Finally, all I had to do was to update my dj startup script to include the same -sname dj -mnesia dir ‘”db”‘ on the command-line, and put the following two lines at the beginning of dj.erl:
mnesia:start() mnesia:create_table(counter, [{disc_copies, [node()]}, {attributes, [key, counter]}])
The end result was the ability to navigate and edit the database in a browser (see screenshot), albeit with a few issues that I’ll sort out next time.

2 comments
Comments feed for this article
Trackback link: http://ciarang.com/posts/erlyweb-mnesia-and-xmerl_xpath/trackback