#!/usr/bin/perl
use XML::XPath;
use strict;

my $xml=qq|<?xml version="1.0" encoding="utf-8"?>
<cdl><structure><assessments>
<component type="labtasks" name="Lab Tasks" id="labtasks"    weight="40"/>
<component type="exam"       name="Mid Term Exam"    id="midterm" weight="20"/>
<component type="exam"       name="End Term Exam"  id="endterm" weight="40"/>
</assessments></structure></cdl>
|;

my (%weights,$res);
my $xp = XML::XPath->new(xml=>$xml);

foreach my $component ($xp->findnodes ('//structure//assessments/component')) 
{
    my $id = $xp->findvalue ('@id',     $component);
    $weights{$id} = $xp->findvalue ('@weight', $component);

    $res=  100 * $weights{$id};	# this is where things fail. 
    print "res is $res\n";
}


