"Deep recursion" error in XML::XPath

"Solutio at Gmail" <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <1E7C0415695A48448C61B64CC8FB2AB3@ICAD820ASAIP>
I would appreciate it if you could help me figure out what could be wrong with my Perl code that builds an XML element, as follows: 

sub _build_PersonName_node {
    my ( $name, $phref ) = @_;
    my $pname = XML::XPath::Node::Element->new($name);

    foreach my $key ( keys %$phref ) {
        $elem = XML::XPath::Node::Element->new($key);
        $text = XML::XPath::Node::Text->new( $phref->{$key} );
        $elem->appendChild($text);
        $pname->appendChild($elem);
    }
    return $pname;
}

sub _build_Person_node {
    my $phref  = $_[0];
    my $person = XML::XPath::Node::Element->new('Person');
    
    warn Dumper($phref), "\n"; # DEBUG

    foreach my $key ( keys %$phref ) {
        if ( $key eq 'Name' ) {
            $elem = XML::XPath::Node::Element->new($key);
            foreach my $nkey ( keys %{ $phref->{$key} } ) {
                warn $elem->toString, "\n"; # DEBUG
                my $pname = _build_PersonName_node( $nkey, $phref->{$key}{$nkey} );
                warn $pname->toString, "\n"; # DEBUG
                $elem->appendChild($pname);
                warn $elem->toString, "\n"; # DEBUG
                $person->appendChild($elem);
                warn $person->toString, "\n"; # DEBUG
            }
        }
        elsif ( $key eq 'DateOfBirth' ) {
            $elem = _build_Date_node( $key, $phref->{$key} );
            $person->appendChild($elem);
            warn $person->toString, "\n"; # DEBUG
        }
        elsif ( $key eq 'Gender' ) {
            $elem = XML::XPath::Node::Element->new($key);
            $text = XML::XPath::Node::Text->new( $phref->{$key} );
            $elem->appendChild($text);
            $person->appendChild($elem);
            warn $person->toString, "\n"; # DEBUG
        }
        else { }
    }
    warn $person->toString, "\n"; # DEBUG
    return $person;
}

Here is what I pass on to the _build_Person_node sub:

$VAR1 = {
          'Gender' => 'M',
          'DateOfBirth' => '1991-06-06',
          'Name' => {
                      'CurrentName' => {
                                         'Middle' => 'A',
                                         'Suffix' => 'III',
                                         'Family' => 'Robinson',
                                         'Given' => 'William'
                                       }
                    }
        };

The warn operators return:

<Person><Gender>M</Gender></Person>
<Person><Gender>M</Gender><DateOfBirth><ExactDateTime>1991-06-06</ExactDateTime></DateOfBirth></Person>
<Name />
<CurrentName><Middle>A</Middle><Suffix>III</Suffix><Family>Robinson</Family><Given>William</Given></CurrentName>

... meaning that apparently appending the 'DateOfBirth' and 'Gender' children to the 'Person' node is not a problem. But the code chokes when appending the 'CurrentName' child to the 'Name' node, failing with the following errors:

Deep recursion on anonymous subroutine at /usr/lib/perl5/site_perl/5.8.8/XML/XPath/Node/Element.pm line 410.
Deep recursion on subroutine "XML::XPath::Node::ElementImpl::toString" at /usr/lib/perl5/site_perl/5.8.8/XML/XPath/Node.pm line 240.

I tried to find an answer on the Internet, but haven't had any luck so far...

Thank you in advance,

Alexander

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.