# -*- Perl -*-

sub getProfileString {
    my ($xmlfile, $section, $variable, $default) = @_;
    local (*F, $_);

    open (F, $xmlfile) || return undef;
    read (F, $_, -s $xmlfile);
    close (F);

    while (/(<section[^>]*>)(.*?)<\/section\s*>/s) {
	my($sectstart) = $1;
	my($sectdata) = $2;
	$_ = $';

	if ($sectstart =~ /name=([\"\'])$section\1/s) {
	    while ($sectdata =~ /<entry[^>]*?\/>/) {
		my($entry) = $&;
		$sectdata = $';
		if ($entry =~ /name=([\"\'])$variable\1/s) {
		    if ($entry =~ /value=([\"\'])(.*?)\1/s) {
			return $2;
		    } else {
			return "";
		    }
		}
	    }
	    return $default;
	}
    }
    
    return $default;
}

1;
    
