Friday, September 19, 2008

"Scoring" an XML File

Ok, here's a project.  I've got, in XML format, the profile of a user.  It's a relatively fixed structure, so for any possible section I'll have at least an empty element for that section.  For instance if the user has no Interests I will have an <Interests/> block, but no <Interest>...</Interest> blocks inside.  There could be 0 or more <Interest> elements.  This is true for a number of sections.

What I want to do is assign a score to each of these sections, and then say "If the section is empty you get no points, otherwise you get X points."  Then, report the total.  If this sounds like the way LinkedIn does profiles, you're exactly right. :)

I'm trying to decide how to proceed.  In this particular case I need something fast and not very disruptive.  The XML is stored in an Oracle database, and the most awesome solution would be something that either runs directly in Oracle, or maybe an XSLT transform.  I could certainly whip something up in Ruby in the time it takes me to blog this, but that's not really an option since we have to factor it into our production environment.  It'll be a heck of a lot easier to just say "Call this stored proc to get the score" then to explain why we need to start installing Ruby on the production boxes.

Anybody got any brilliant ideas?  I'm trying to XSLT solution, directly in Oracle, but it's not going smoothly.  I'm wondering if there's enough flexibility in XSLT to do this level of math.

1 comment:

steveo said...

There exists an elegant solution for almost anything. For everything else there is XML.

This sounds like the perfect opportunity to take your data out of XML in your database so that you can actually query it.