+sub Hash2grs {
+ my ($self, $href, $mapping) = @_;
+ my $key;
+ my $content;
+ my $aref;
+
+ $mapping = defined($mapping) ? $mapping : $self->{MAP};
+ foreach $key (keys %$href) {
+ $content = $href->{$key};
+ if (!defined($aref = $mapping->{$key})) {
+ print STDERR "Hash2grs: Unmapped key: '$key'\n";
+ next;
+ }
+ if (ref($content) eq 'HASH') { ## Subtree?
+ my $subtree = new Net::Z3950::GRS1($content);
+ $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::Subtree, $subtree);
+ } elsif (ref($content) eq '') { ## Regular string?
+ $self->AddElement($aref->[0], $aref->[1], &Net::Z3950::GRS1::ElementData::String, $content);
+ } else {
+ print STDERR "Hash2grs: Unsupported content type\n";
+ next;
+ }
+ }
+}